| 1 | # 8-Bit CPU Emulator |
| 2 | |
| 3 | ## CPU Architecture |
| 4 | - Word Size |
| 5 | - **Data Width:** 8 bits |
| 6 | - **Address width:** 16 bits |
| 7 | - **Address space:** 64 KB (0x0000-0xFFFF) |
| 8 | |
| 9 | ## Supported Instructions |
| 10 | |
| 11 | | Instruction | Syntax | |
| 12 | | ----------- | ---------------- | |
| 13 | | MOV | mov dest, src OR mov reg, imm | |
| 14 | | ADD | add r1, r2 OR add reg, imm | |
| 15 | | SUB | sub r1, r2 OR sub reg, imm | |
| 16 | | JMP | jmp addr OR jmp addr | |
| 17 | | JZ | jz addr OR jz addr | |
| 18 | | JNZ | jnz addr OR jnz addr | |
| 19 | | CMP | cmp r1, r2 OR cmp reg, imp | |
| 20 | | MUL | mul r1, r2 | |
| 21 | | DIV | div r1, r2 | |
| 22 | | CALL | call \<label\> | |
| 23 | | SYS | sys \<syscall_no\> | |
| 24 | | HLT (Halt) | hlt | |
| 25 | |
| 26 | |
| 27 | ## Registers |
| 28 | | Register | Size | Description | |
| 29 | | -------- | ------ | ------------------------------ | |
| 30 | | A | 8-bit | General | |
| 31 | | B | 8-bit | General | |
| 32 | | C | 8-bit | General | |
| 33 | | D | 8-bit | General | |
| 34 | | PC | 16-bit | Program Counter | |
| 35 | | SP | 16-bit | Stack pointer | |
| 36 | |
| 37 | |
| 38 | ## Flags |
| 39 | | Flag | Description | |
| 40 | | ----- | ------------ | |
| 41 | | Z | Zero Flag | |
| 42 | | C | Carry/Borrow | |
| 43 | |
| 44 | |
| 45 | ## Syscalls |
| 46 | | Imm | Meaning | |
| 47 | | --- | ------- | |
| 48 | | 0 | Exit Program | |
| 49 | | 1 | Print register A as integer | |
| 50 | | 2 | Print register A as ASCII char | |
| 51 | |
| 52 | |
| 53 | # Usage |
| 54 | ```bash |
| 55 | cargo run -- --f <examples/filename.asc> |
| 56 | ``` |
| 57 | |
| 58 | ## Todo |
| 59 | - [x] Assembler |
| 60 | - [x] Lexer/Tokenizer |
| 61 | - [x] Add label support (supporting JMP/JZ/JNZ) |
| 62 | - [x] Add instructions |
| 63 | - [x] CMP |
| 64 | - [x] MUL |
| 65 | - [x] DIV |
| 66 | - [x] CALL |
| 67 | - [x] RET |
| 68 | - [x] SYS |
| 69 | - [ ] Better Error handling |
| 70 | - [ ] TUI Debugger |