Next goes here. Memory goes here. |
|
Labels Debug |
This simulation attempts to replicate the operation of Ben Eater's 8-bit Computer.
The simulation contains buttons and dip switches on the virtual computer similar to those on Ben's physical computer. These can be used to load memory, start, stop, and step the clock, and reset the computer. In other words, they contain all of the functionality needed to run the computer.
This simulation also contains additional capabilities to write programs as either source code or hex code and to load that code into memory for execution. It also contains convenient controls for loading pre-written programs, running, stopping, and resetting the computer.
The easiest way to get started is to simply click the Green "Run/Stop" button. The simulation is initially pre-loaded with Ben's Fibonacci program which will start running and repeatedly display the numbers 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233. The simulation can be stopped and continued with the "Run/Stop" button. It can also be reset with the "Reset" button.
Beyond the default Fibonacci program, the simulation contains an "Examples" selector that allows loading of other demonstration programs for counting, adding, and multiplying. Selecting any of those programs will load the source code into the "Source Code" text box. They will still need to be assembled and loaded before being run. Simply click the "Assemble" button to assemble the code in the "Source Code" box placing the result in the "Hex Code" box. The hex code can then be loaded into the computer's memory with the "Load" button at the top of the "Hex Code" box (note that it's best to stop any simulation before loading new hex code into memory). Once the code has been assembled and loaded, the computer can optionally be reset again with the "Reset" button. This process is as follows:
This process can be followed for each example program.
Of course, you can also write your own programs in either assembly language (in the "Source Code" box) or in plain hex (in the "Hex Code" box). The full instruction set is available through the "Additional Information" drop down box above. Note that programs are not saved, so they should be copied and saved in an external file to preserve anything you write.
You can also interact with the controls on the computer itself. This is most easily done by checking the "Labels" check box below the "Source Code" box. The "Labels" check box controls the showing or hiding of the yellow labels that reference the various controls on the computer. Showing the labels makes it much easier to directly program the computer. The labels should show:
The programming steps below will use the labels to guide you through programming a simple counting program. The counting program is shown in the form of a listing here (address, op code, assembly code):
0 51 LDI 1 1 4F STA F 2 50 LDI 0 3 2F ADD F 4 E0 OUT 5 63 JMP 3
In other words, you will want to program the hex value of "51" at address "0", the value of "4F" at address "1", the value of "50" at address "2", and so on. The steps below will walk you through the process. Note that it the DIP switches will show black for a 0, and white for a 1. Also note that these switches are very small, and it helps to zoom in your web browser window to make it easier to click on them. It might also help to open a second browser window so that you can view these steps in one window while working with the computer in another window (without scrolling up and down). Follow these steps to program the counting program listed above (remember all controls refer those INSIDE the computer image itself):
At this point, the computer should be counting along at a reasonable pace. You can change the clock speed by clicking on the "CLOCK SPEED" control in the upper left. That button will cycle through 4 different speeds:
You can also single step the clock by toggling off the "RUN/STOP" button (if already running), and then clicking the "STEP" button for each clock pulse.
Ideally, this computer should be bit-for-bit identical to Ben's computer. However, this has not been confirmed, and the simulation code does not (yet) operate at the gate level. So there are likely to be some differences. In fact, there are actually three levels of simulation code in this program. There's a "Macro" level (which doesn't use microcode at all), a "Micro1" level, and a "Micro2" level. The default is currenly set to "Micro1" which is not yet as close to the hardware as desired. These different simulation levels can be explored by checking the "Debug" checkbox below the "Source Code" box. Checking "Debug" does two things. First, it enables various "console.log" print statments which may be visible in your browser's Development Tools window. Second, it will show a level selection box in the upper right corner of the Computer window. This box can be clicked to cycle through the three simulation levels ("Macro" is blue, "Micro1" is green, and "Micro2" is red). Note that this is a temporary feature until the simulation can be completed and verified.
Name | Hex | Binary | Description |
NOP | 0x | 0000 xxxx | No operation (does nothing) |
LDA | 1a | 0001 addr | Load from memory (addr) into A Register |
ADD | 2a | 0010 addr | Add from memory (addr) into A Register |
SUB | 3a | 0011 addr | Subtract memory (addr) from A Register |
STA | 4a | 0100 addr | Store to memory (addr) from A Register |
LDI | 5v | 0101 value | Load immediate value into A Register |
JMP | 6a | 0110 addr | Jump immediate |
JC | 7a | 0111 addr | Jump on carry immediate |
JZ | 8a | 1000 addr | Jump on zero immediate |
--- | 9? | 1001 ???? | Not defined |
--- | A? | 1010 ???? | Not defined |
--- | B? | 1011 ???? | Not defined |
--- | C? | 1100 ???? | Not defined |
--- | D? | 1101 ???? | Not defined |
OUT | Ex | 1110 xxxx | Output to LED panel (could use XXXX for In/Out channels) |
HLT | Fx | 1111 xxxx | Halt (could use XXXX for other instructions, push, pop, chs, etc.) |