This project is a simulation of a computer based upon logic gates constructed from telegraph relays. The inspiration and design of the computer come from Charles Petzold's book CODE: The Hidden Language of Computer Hardware and Software.
There are several different machines implemented in this project. Each of these machines corresponds to one of the machines described in Charles Petzold's book. Most of these machines cannot be classified as computers, but represent stepping stones on the way to the implementation of an actual computer.
This machine implementation is a complete implementation of the computer described in chapter 17 of Charles Petzold's book, plus three additional bitwise operators.
This is not a fast computer. Each clock cycle takes several milliseconds, where modern electronic computers have clock cycles on the order of nanoseconds. There is an additional pause of 10 milliseconds between each clock cycle. A simple multiplication program operating by repeated addition can take most of a day to run, and on slower computers can actually take even longer to run. The reason for this machine isn't speed, but to demonstrate how a computer works from the ground up.
These instructions require three bytes, the opcode, the high-order byte of the 16-bit address, and the low order byte of the 16-bit address. The instruction mnemonic code, hexadecimal opcode, binary opcode, and description are given in order for each instruction.
| Mnemonic | Hex opcode | Binary Opcode | Description |
|---|---|---|---|
| LOD | 10 | 0001 0000 | Load byte into accumulator |
| STO | 11 | 0001 0001 | Store byte in accumulator to memory |
| ADD | 20 | 0010 0000 | Add byte to accumulator |
| SUB | 21 | 0010 0001 | Subtract byte from accumulator |
| ADC | 22 | 0010 0010 | Add byte to accumulator, with carry input |
| SBB | 23 | 0010 0011 | Subtract byte from accumulator, with borrow |
| JMP | 30 | 0011 0000 | Unconditional jump |
| JZ | 31 | 0011 0001 | Jump if zero |
| JC | 32 | 0011 0010 | Jump if carry |
| JNZ | 33 | 0011 0011 | Jump if not zero |
| JNC | 34 | 0011 0100 | Jump if not carry |
| OR | 40 | 0100 0000 | Bitwise OR byte in accumulator with memory |
| AND | 41 | 0100 0001 | Bitwise AND byte in accumulator with memory |
| XOR | 42 | 0100 0010 | Bitwise XOR byte in accumulator with memory |
These instructions require one byte, the Opcode.
| Mnemonic | Hex opcode | Binary Opcode | Description |
|---|---|---|---|
| HLT | ff | 1111 1111 | Halt processor |
This computer uses a primitive interface consisting of a control panel with toggle switches for inputs and lamps for outputs. To enter and run a new program:
- Flip the "RESET" switch into the "ON" position (up).
- Flip the "TAKE OVER" switch into the "ON" position. The control panel is now ready for you to enter your program.
- Enter the address where you wish to store a byte of data by flipping the appropriate switches labeld "A0" through "AF" (from right to left) into the "ON" or "OFF" (down) position.
- Specify the byte of data by flipping the appropriate switches labeled "D0" through "D7" into the "ON" or "OFF" position.
- Enter the byte of data into memory by flipping the "WRITE" switch into the "ON" position. The row of lamps beneath the data switches ("D0" through "D7") will light up indicating which bits of the memory location are on and which are off. They should match the data switch positions, each switch that is on should have a corresponding lit lamp.
- Flip the "WRITE" switch into the "OFF" position before entering your next address or data byte. If you fail to do this you will be writing the byte corresponding to the data switches into each address corresponding to the address switches as you toggle the address or data switches. This can potentially overwrite data that you have already entered.
- Repeat steps 3 through 5, entering each byte of the program into memory.
- Flip the "TAKE OVER" switch into the "OFF" position.
- Flip the "RESET" switch into the "OFF" position. Your program will now run. If you have entered everything correctly using the switches you will see the bank of lamps at the bottom fo the control panel start flashing for a while. If your program runs to completion (in other words, it reaches a HLT instruction during a code fetch cycle) the bank of lamps will stop flashing and the "HALT" lamp will turn on. This is your indication that your program has completed execution.
- Flip the "RESET" switch into the "ON" position. This will prevent the computer from performing random operations while you inspect the results.
- Flip the "TAKE OVER" switch into the "ON" position. The control panel switches are now active.
- Inspect the results of running your program by entering the addresses of the bytes you wish to inspect on the bank of address switches. As each switch is toggled the byte at the memory location corresponding to the address switches will be displayed on the bank of data lamps.
