Builds for Windows and Linux are available here.
$ mkdir build && cd build
$ cmake ..
$ cmake --build . --config Release
Requires compiler fully supporting std::filesystem.
$ ./von-neumann [OPTION...]
-h, --help Show help
-f, --file arg Path to the VNM program file
-c, --counter arg Set initial program counter value
-s, --save Save output to file
-r, --register Print register values before every cycle
-m, --memory Print memory before every cycle
-b, --binary Print instruction arguments in binary
-d, --signed Print instruction arguments as 9-bit signed integers
Example:
$ ./von-neumann -rmf example/array_sum.vnm
-
Memory of 512 16-bit words, addressed from 0 to 511.
-
Four 16-bit registers
- Accumulator (
AC) - Operand register (
OR) - Program counter (
PC) - Instruction register (
IR)
- Accumulator (
STOP, code:0000, stops the machineLOAD, code:0001, operation:AC = ORSTORE, code:0010, operation:MEM[ OR ] = ACJUMP, code:0011, operation:PC = ORJNEG, code:0100, operation:AC < 0 => PC = ORJZERO, code:0101, operation:AC == 0 => PC = ORADD, code:0110, operation:AC = AC + ORSUB, code:0111, operation:AC = AC - ORMULT, code:1000, operation:AC = AC * ORDIV, code:1001, operation:AC = AC / ORAND, code:1010, operation:AC = AC & OROR, code:1011, operation:AC = AC | ORNOT, code:1100, operation:AC = ~ORCMP, code:1101, operation:AC == OR => AC = -1,AC != OR => AC = 0SHZ, code:1110, operation:OR < 0 => AC >> |OR|,OR > 0 => AC << |OR|SHC, code:1111, circular shift left or right, depending on the sign of the operand
- Instant, code:
00,$, operation:OR = IR.arg - Direct, code:
01,@, operation:OR = MEM[ IR.arg ] - Indirect, code:
10,&, operation:OR = MEM[ MEM[ IR.arg ] ] - Index, code:
11,+, operation:OR = MEM[ AC + IR.arg ]
- 16 bits
- Most significant bit - farthest to the left left, unused
- Next four bits - instruction code (
IR.code) - Next two bits - addressing mode code (
IR.mode) - Remaining nine bits - instruction argument (
IR.arg)
0. LOAD @ 5 ; instructions begin
1. ADD @ 6 ;
2. MULT $ 2 ;
3. STORE $ 7 ;
4. STOP ; instructions end
5. 21 ; first data
6. 34 ; second data
7. 0 ; result0. LOAD $ 0
1. STORE $ 19
2. LOAD $ 21
3. STORE $ 18
4. LOAD $ 21
5. ADD @ 20
6. SUB @ 18
7. JZERO $ 15
8. LOAD @ 19
9. ADD & 18
10. STORE $ 19
11. LOAD @ 18
12. ADD $ 1
13. STORE $ 18
14. JUMP $ 4
15. STOP
16.
17.
18. ; auxiliary memory
19. ; result
20. 5 ; number of elements in sequence: n
21. 10 ; first element: array[ 0 ]
22. 20 ; second element: array[ 1 ]
23. 30 ; ...
24. 40 ; ...
25. 50 ; last element: array[ n - 1 ]
Machine specification was based on Przykładowa maszyna cyfrowa (PMC) as defined in the book below.
Kawa, R., & Lembas, J. (2017). "Wykłady z informatyki: Wstęp do informatyki". Warszawa: Wydawnictwo Naukowe PWN.