This is a C# implementation of the book The Elements of Computing Systems by Noam Nisan & Shimon Schocken. Instead of grabbing a soldering iron, all the logic is done with C# implementations of logical gates to simulate it as much as possible.
Start the .NET core console application in project CS.Architecture.App.
Below is a list with the current contents of the project.
- Nand
- Not
- And
- Or
- Xor
- And3
- And16
- Not16
- Or16
- Or8Way
- Mux
- Mux16
- Mux4Way16
- Mux8Way16
- DMux
- DMux16
- DMux4Way16
- DMux8Way16
- HalfAdder
- FullAdder
- Adder16
- Inc16
- ALU
- Clock
- DFF
- Bit
- Register
- RAM8
- RAM64
- RAM512
- RAM4K
- RAM16K
- PC (16-bit counter)
WIP
- CPU
- ROM32K
- Screen
- Keyboard
- Memory
- Computer
A-instruction
Instruction @value
causes the computer to store the specified value in the A register.
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | x |
Bit 15
indicates the A-instruction. x
represents the value.
Used for:
- Constants
- Memory manipulation
- Jump instructions
C-instruction
Instruction dest=comp;jump
causes the computer to execute a computation.
- if
dest
is empty, the=
is omitted. - if
jump
is empty, the;
is omitted.
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | a | c1 | c2 | c3 | c4 | c5 | c6 | d1 | d2 | d3 | j1 | j2 | j3 |
Bit 15
indicates the C-instruction. Bit 14
& 13
are not used and left at 1
.
Compute
Computed function is specified by the a
-bit and six c
-bits.
comp (a=0) | c1 | c2 | c3 | c4 | c5 | c6 | comp(a=1) |
---|---|---|---|---|---|---|---|
0 |
1 | 0 | 1 | 0 | 1 | 0 | |
1 |
1 | 1 | 1 | 1 | 1 | 1 | |
-1 |
1 | 1 | 1 | 0 | 1 | 0 | |
D |
0 | 0 | 1 | 1 | 0 | 0 | |
A |
1 | 1 | 0 | 0 | 0 | 0 | M |
!D |
0 | 0 | 1 | 1 | 0 | 1 | |
!A |
1 | 1 | 0 | 0 | 0 | 1 | !M |
-D |
0 | 0 | 1 | 1 | 1 | 1 | |
-A |
1 | 1 | 0 | 0 | 1 | 1 | -M |
D+1 |
0 | 1 | 1 | 1 | 1 | 1 | |
A+1 |
1 | 1 | 0 | 1 | 1 | 1 | M+1 |
D-1 |
0 | 0 | 1 | 1 | 1 | 0 | |
A-1 |
1 | 1 | 0 | 0 | 1 | 0 | M-1 |
D+A |
0 | 0 | 0 | 0 | 1 | 0 | D+M |
D-A |
0 | 1 | 0 | 0 | 1 | 1 | D-M |
A-D |
0 | 0 | 0 | 1 | 1 | 1 | M-D |
D&A |
0 | 0 | 0 | 0 | 0 | 0 | D&M |
D|A |
0 | 1 | 0 | 1 | 0 | 1 | D|M |
Destination
Stores the computed value.
d1
in the A registerd2
in the D registerd3
in memory
d1 | d2 | d3 | Mnemonic | Destination |
---|---|---|---|---|
0 | 0 | 0 | null |
Value is not stored |
0 | 0 | 1 | M |
Memory[A] (memory register addressed by A) |
0 | 1 | 0 | D |
D register |
0 | 1 | 1 | MD |
Memory[A] and D register |
1 | 0 | 0 | A |
A register |
1 | 0 | 1 | AM |
A register and Memory[A] |
1 | 1 | 0 | AD |
A register and D register |
1 | 1 | 1 | AMD |
A register, Memory[A], and D register |
Jump
Change the PC to jump to another instruction.
j1 (out < 0) | j2 (out = 0) | j3 (out > 0) | Mnemonic | Effect |
---|---|---|---|---|
0 | 0 | 0 | null |
No jump |
0 | 0 | 1 | JGT |
If out > 0 jump |
0 | 1 | 0 | JEQ |
If out = 0 jump |
0 | 1 | 1 | JGE |
If out >= 0 jump |
1 | 0 | 0 | JLT |
If out < 0 jump |
1 | 0 | 1 | JNE |
If out != 0 jump |
1 | 1 | 0 | JLE |
If out <= jump |
1 | 1 | 1 | JMP |
Jump |
TBA
TBA
TBA