bench515d34df5
modify README.md
+72 −29
1 file changed
- M README.md +72 −29
| @@ -1,10 +1,46 @@ | |||
| 1 | 1 | # 8-Bit CPU Emulator | |
| 2 | 2 | ||
| 3 | − | ## CPU Architecture | |
| 4 | − | - Word Size | |
| 5 | − | - **Data Width:** 8 bits | |
| 6 | − | - **Address width:** 16 bits | |
| 7 | − | - **Address space:** 64 KB (0x0000-0xFFFF) | |
| 3 | + | This project is an educational 8-bit CPU emulator written in Rust, it's build to understand core computer architecture concepts such as instruction sets, flags, | |
| 4 | + | control flow, stacks and system calls. | |
| 5 | + | ||
| 6 | + | This project is **not** a production CPU and **not** accurate. It is designed purely for learning and experimentation. | |
| 7 | + | ||
| 8 | + | ----- | |
| 9 | + | ||
| 10 | + | ## Features | |
| 11 | + | ||
| 12 | + | - Custom 8-bit ISA (control-flow and arithmetic operations) | |
| 13 | + | - 4 general-purpose registers | |
| 14 | + | - 64 KB (0x0000-0xFFFF) byte-addressable memory | |
| 15 | + | - Two-pass assembler with label support | |
| 16 | + | - Stack-based function calls | |
| 17 | + | - Stack is software-managed and grows downward | |
| 18 | + | ||
| 19 | + | --- | |
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ## Registers | |
| 24 | + | | Register | Size | Description | | |
| 25 | + | | -------- | ------ | ------------------------------ | | |
| 26 | + | | A | 8-bit | General-purpose register | | |
| 27 | + | | B | 8-bit | General-purpose register | | |
| 28 | + | | C | 8-bit | General-purpose register | | |
| 29 | + | | D | 8-bit | General-purpose register | | |
| 30 | + | | PC | 16-bit | Program Counter | | |
| 31 | + | | SP | 16-bit | Stack pointer | | |
| 32 | + | ||
| 33 | + | ||
| 34 | + | ## Flags Register | |
| 35 | + | ||
| 36 | + | The CPU maintains a small flags register. | |
| 37 | + | ||
| 38 | + | | Flag | Description | | |
| 39 | + | | ----- | ------------ | | |
| 40 | + | | Z | Zero flag - set if last result was `0` | | |
| 41 | + | | C | Carry/Borrow flag | | |
| 42 | + | ||
| 43 | + | - Control-flow instructions do **not** modify flags. | |
| 8 | 44 | ||
| 9 | 45 | ## Supported Instructions | |
| 10 | 46 | ||
| @@ -21,41 +57,48 @@ | |||
| 21 | 57 | | DIV | div r1, r2 | | |
| 22 | 58 | | CALL | call \<label\> | | |
| 23 | 59 | | 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 | − | ||
| 60 | + | | HLT (Halt) | hlt | | |
| 44 | 61 | ||
| 45 | 62 | ## Syscalls | |
| 63 | + | ||
| 46 | 64 | | Imm | Meaning | | |
| 47 | 65 | | --- | ------- | | |
| 48 | 66 | | 0 | Exit Program | | |
| 49 | 67 | | 1 | Print register A as integer | | |
| 50 | 68 | | 2 | Print register A as ASCII char | | |
| 51 | 69 | ||
| 70 | + | - Syscalls also do not modify flags | |
| 71 | + | ||
| 72 | + | ## Example assembly program | |
| 73 | + | ||
| 74 | + | ```assembly | |
| 75 | + | mov b, 3 | |
| 76 | + | mov a, 1 | |
| 77 | + | ||
| 78 | + | loop: | |
| 79 | + | sub b, a | |
| 80 | + | jnz loop | |
| 81 | + | ||
| 82 | + | sys 1 ; print register A | |
| 83 | + | sys 0 ; exit | |
| 84 | + | ``` | |
| 85 | + | ||
| 86 | + | ## Usage | |
| 52 | 87 | ||
| 53 | − | # Usage | |
| 54 | 88 | ```bash | |
| 55 | 89 | cargo run -- --f <examples/filename.asc> | |
| 56 | 90 | ``` | |
| 57 | 91 | ||
| 58 | − | ## Todo | |
| 92 | + | ## Non-goals | |
| 93 | + | ||
| 94 | + | 1. No pipelining | |
| 95 | + | 2. No interrupts | |
| 96 | + | 3. No virtual memory | |
| 97 | + | 4. No privilege levels | |
| 98 | + | 5. No hardware I/O | |
| 99 | + | ||
| 100 | + | ## Goals | |
| 101 | + | ||
| 59 | 102 | - [x] Assembler | |
| 60 | 103 | - [x] Lexer/Tokenizer | |
| 61 | 104 | - [x] Add label support (supporting JMP/JZ/JNZ) | |
| @@ -66,5 +109,5 @@ cargo run -- --f <examples/filename.asc> | |||
| 66 | 109 | - [x] CALL | |
| 67 | 110 | - [x] RET | |
| 68 | 111 | - [x] SYS | |
| 69 | − | - [ ] Better Error handling | |
| 70 | − | - [ ] TUI Debugger | |
| 112 | + | - [ ] Better error-handling | |
| 113 | + | - [ ] TUI debugger | |