Emulating the nandgame processor with its simplistic instruction set in C. Gonna modify it a bit ofc.
- It's a 16 bit processor
- 16 bit Data BUS
- It has 2 16-bit A and D, as well as a program counter
- First time i do something like this. Tokenization is pretty not good; Its not case sensitive at least
- It works with uint16s, not with int16
The instruction encoding is almost 1:1 as the CPU you create in the nandgame.
One observation you can make is that the 15th and 14th bit are being unused. I made them so that:
Processor goes into dump mode and dumps A reg into std out as a DIGIT
If 14 is high as well it tries to dump it as a char from ASCII
LOAD <uint16_t>
- Loads number in A reg
MOV <src-reg> <A/*A/D dest-regs>
- Copies value from src-reg to all registers in dest. Example: MOV A A D *A
DUMPC
- explained above
DUMPD
- explained above
ADD A D D
JGE
It wont look at result from first instruction, but of result of instruction with no params which i think is bitwise AND
of A and D.
JMP
- Unconditional
JGE
- Jump greater or equal
JGT
- Jump greater
JEQ
- Jump equal
<INST> <ARGS>[; <Jump condition>]
with example: ADD A D D; JGE
ADD <src-reg1> <src-reg2> <A/*A/D dest-regs>
- sums up src-reg1
and src-reg2
and copies the result in dest-regs
SUB <src-reg1> <src-reg2> <A/*A/D dest-regs>
- subtracts from src-reg1
src-reg2
and copies the result in dest-regs
AND <src-reg1> <src-reg2> <A/*A/D dest-regs>
- performs bitwise and on src-reg1
and src-reg2
and copies the result in dest-regs
OR <src-reg1> <src-reg2> <A/*A/D dest-regs>
- performs bitwise and on src-reg1
or src-reg2
and copies the result in dest-regs
INV <src-reg> <A/*A/D dest-regs>
- performs bitwise inversion on src-reg
and copies the result in dest-regs
Use whatever compiler you want on main.c
You can assemble using ./<program> asm <file-path> [dest-path]
You can emulate the then assembled file by doing ./<progra> emulate <file-path>