GithubHelp home page GithubHelp logo

bcpu's Introduction

bcpu

An emulator for a CPU with any instruction size. Made for experimentation

Why?

This is mostly just an experiment with writing bytecode. I can't think of a practical use for this. It's probably going to end up being terribly slow, but in my defense, Java seems to work just fine, although it doesn't artificially slow itself down with aribtrary instruction sizes. Alas, I long for the day when CPUs will have this functionality. I'm not an engineer so there's probably a good reason why this will never happen.

How to Use

I plan to eventually create an assembler for this, but here's how the bitcode works.

An Instruction

Instruction Code - 5 bits

Instruction Size - 6 bits

Location (Memory | Constant) - 1 bit

Memory Address (Up to 2.3e18 bytes supported) - 64 bits

Instructions

MOV (destination source)
ADD (location op1 op2)
SUB (location op1 op2)
MUL (location op1 op2)
DIV (location op1 op2)
MOD (location op1 op2)
ADDI (location op1 op2)
SUBI (location op1 op2)
MULI (location op1 op2)
DIVI (location op1 op2)
MODI (location op1 op2)
ADDF (location op1 op2)
SUBF (location op1 op2)
MULF (location op1 op2)
DIVF (location op1 op2)
MODF (location op1 op2)
AND (location op1 op2)
OR (location op1 op2)
XOR (location op1 op2)
NOT (location op)
CMP (op1 op2)
CMPI (op1 op2)
CMPF (op1 op2)
JEQ (instruction)
JNE (instruction)
JGT (instruction)
JLT (instruction)

# Yeah, I know these definitely wouldn't work. They're only here for my convenience

PRINT (string_size location)
PRINTC (char)
PRINTN (number)
PRINTI (number)
PRINTF (number)

Registers

Register ip - Instruction pointer

Register sp - Stack Pointer

Register ps - Program Status Register

Program Status Register

2 bits for comparison (Error | Greater | Less | Equal)

1 bit for divide by zero flag

1 bit for carry flag

1 bit for zero flag

1 bit for sign flag

1 bit for overflow flag

Rest are reserved

bcpu's People

Contributors

botahamec avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.