51
This repository contains an 8-bit virtual machine implementation, complete with an assembler and an instruction set.
The Byte Machine features a 16-bit address space, allowing it to address up to 65535 memory locations. Each memory location holds an 8-bit value (u8).
The opcode is 4bit long which gives us 16 number of opcodes to have in byte machine. There are 3 layout of instructions 1 byte, 2 bytes and 3 byte instructions generally the 3 bytes instruction are the ones which store the memory address.
Registers
The Byte Machine includes a set of 8 registers:
A, B, C, D: General-purpose 8-bit registers.
SP (Stack Pointer): Points to the top of the stack.
PC (Program Counter): Holds the address of the next instruction to be executed.
BP (Base Pointer): Used for base-relative addressing in stack operations.
Flags: A special register for condition flags like Zero and Overflow.
Assembler
The assembler is a single file which just writes the byte equivelent of the instructions which the vm can understand and it just dumps that to the stdout, so please note you have redirect that to seperate file.
The assembler takes care of the lables beautifully btw, it just goes through the code ones(pass one) and actually stores the lables and their respective memory address in the hashmap and during the second pass whereever it come accross those jump statement it just replace those lables with the memory address stored in the hashmap.
Built with