# simple-computer **Repository Path**: flanche/simple-computer ## Basic Information - **Project Name**: simple-computer - **Description**: No description available - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-10-05 - **Last Updated**: 2024-09-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Simple Computer Whilst reading [_But How Do It Know?_](http://buthowdoitknow.com/) by J. Clark Scott I felt compelled to write something to simulate the computer the book describes. Starting from NAND gates, and moving up through to registers, RAM, the ALU, the control unit and adding I/O support, I eventually ended up with a fully functional machine. All the components of the system are based on logic gates and the way they are connected together via the system bus. For a write up about this project, see my blog post about it here https://djharper.dev/post/2019/05/21/i-dont-know-how-cpus-work-so-i-simulated-one-in-code/ ![text writer](_programs/screenshots/text-writer.png) # Specs - `~0.006mhz` - at least on my machine - 16-bit - the book describes an 8-bit CPU for simplicity but I wanted more RAM and there is only one system bus - 65K RAM - 240x160 screen resolution - 4x 16-bit registers (`R0`, `R1`, `R2`, `R3`) Missing features - Interrupts, so you have to write awful polling code - The book does shortly describe how to extend the system to support interrupts but would involve a lot more wiring - Stack pointer register + stack + stack manipulation instructions so nested `CALL` instructions won't work and registers may be left in an inconsistent state - Hard drive - Subtract instruction - `MOV` instruction - Floating point math (lol) - Everything else you could think of from a modern CPU Bonus features - No Meltdown/SPECTRE risk - Can easily overwrite any portion of memory without any protective mode getting in the way - Currently incapable of accessing the internet - I can see how you might write a simple networking I/O adapter, although I'd imagine it would be tedious writing the assembly to get bytes in and out of it 🤔 # Instructions | Instruction | Type | Description | Example | | -------------- | --------- | ------------- | ------------- | | `LOAD Ra, Rb` | Machine | Load value of memory address in register A into register B | `LOAD R1, R2` | | `STORE Ra, Rb` | Machine | Store value of register B into memory address in register A | `STORE R3, R1` | | `DATA Ra, ` | Machine | Put `` into register A. `` can either be a symbol, prefixed with `%` (e.g. `%LINE-X`) or a numeric value (e.g. `0x00F2` or `23`) | `DATA R3, %KEYCODE` | | `JR Ra` | Machine | Jump to instruction in memory address in register A | `JR R2` | | `JMP