Update README.md

This commit is contained in:
mrbobbyguy authored and GitHub committed 2026-09-05 23:52:20 -05:00
1 parent 795e829e6a
commit dc35eb4ae8
1 file changed
+64 -70
+64 -70
View File
@@ -2,100 +2,94 @@
extremely simple custom 16 bit cpu emulator and assembler as seen on youtube: https://youtu.be/tlIqosU75CQ?is=ZAVWsYRDMPrUKOej extremely simple custom 16 bit cpu emulator and assembler as seen on youtube: https://youtu.be/tlIqosU75CQ?is=ZAVWsYRDMPrUKOej
use at your own risk! code is thoroughly untested so if you find any bugs let me know asap so i can fix them asap use at your own risk! code is thoroughly untested so if you find any bugs let me know asap so i can fix them asap
BOB-16 # INSTRUCTION SEMANTICS
written by misterbob (instructions are in order of opcode, nop is 0, add is 1, etc.)\
you are free to use and modify this but PLEASE credit me (at least retain the name in some way) (instructions with a * change condition codes)\
** read all of the docs before using as they contain some important tidbits ** NOP: does nothing other than go through a cpu cycle\
**** INSTRUCTION SEMANTICS **** *ADD (normal normal): r[dst] = r[src1] + r[src2]\
(instructions are in order of opcode, nop is 0, add is 1, etc.) ex. add r0 r1 r2\
(instructions with a * change condition codes)
NOP: does nothing other than go through a cpu cycle *ADD (normal immediate): r[dst] = r[src1] + imm[4]\
ex. add r0 r1 4\
*ADD (normal normal): r[dst] = r[src1] + r[src2] *ADD (in place normal): r[dst] += r[src1]\
ex. add r0 r1 r2 ex. add r0 r1\
*ADD (normal immediate): r[dst] = r[src1] + imm[4] *ADD (in place immediate): r[dst] += imm[7]\
ex. add r0 r1 4 ex. add r0 4\
*ADD (in place normal): r[dst] += r[src1] *AND (normal normal): r[dst] = r[src1] & r[src2]\
ex. add r0 r1 ex. and r0 r1 r2\
*ADD (in place immediate): r[dst] += imm[7] *AND (normal immediate): r[dst] = r[src1] & imm[4]\
ex. add r0 4 ex. and r0 r1 4\
*AND (normal normal): r[dst] = r[src1] & r[src2] *AND (in place normal): r[dst] &= r[src1]\
ex. and r0 r1 r2 ex. and r0 r1\
*AND (normal immediate): r[dst] = r[src1] & imm[4] *AND (in place immediate): r[dst] &= imm[7]\
ex. and r0 r1 4 ex. and r0 4\
*AND (in place normal): r[dst] &= r[src1] *NOT (normal): r[dst] = !r[src]\
ex. and r0 r1 ex. not r0 r1\
*AND (in place immediate): r[dst] &= imm[7] *NOT (immediate): !r[dst]\
ex. and r0 4 ex. not r1\
*NOT (normal): r[dst] = !r[src] *LD: r[dst] <= memory[pc + imm[9]]\
ex. not r0 r1 ex. ld r0 15\
*NOT (immediate): !r[dst] *LDI: r[dst] <= memory[memory[pc + imm[9]]\
ex. not r1 ex. ldi r0 15\
*LD: r[dst] <= memory[pc + imm[9]] *LDR: r[dst] <= memory[r[src] + imm[6]]\
ex. ld r0 15 ex. ldr r0 r1 15\
*LDI: r[dst] <= memory[memory[pc + imm[9]] ST: r[src] => memory[pc + imm[9]]\
ex. ldi r0 15 ex. st r0 15\
*LDR: r[dst] <= memory[r[src] + imm[6]] STI: r[src] => memory[memory[pc + imm[9]]\
ex. ldr r0 r1 15 ex. sti r0 15\
ST: r[src] => memory[pc + imm[9]] STR: r[src] => memory[r[dst] + imm[6]]\
ex. st r0 15 ex. str r0 r1 15\
STI: r[src] => memory[memory[pc + imm[9]] BR: if condition codes match any of the nzp flags, pc += imm[9]\
ex. sti r0 15 ex. br np 50\
(jumps to incremented pc + 50 if condition codes n or p are 1)\
STR: r[src] => memory[r[dst] + imm[6]] JMP: pc = r[src]\
ex. str r0 r1 15 ex. jmp r0\
BR: if condition codes match any of the nzp flags, pc += imm[9] JSR: r[7] = pc, pc += imm[11]\
ex. br np 50 ex. jsr 50\
(jumps to incremented pc + 50 if condition codes n or p are 1)
JMP: pc = r[src] JSRR: r[7] = pc, pc = r[src]\
ex. jmp r0 ex. jsrr r0\
JSR: r[7] = pc, pc += imm[11] *LEA: r[src] = pc\
ex. jsr 50 ex. lea r0\
JSRR: r[7] = pc, pc = r[src] RET: pc = r[7]\
ex. jsrr r0 ex. ret\
*LEA: r[src] = pc TRAP (vector 0): halts program\
ex. lea r0 TRAP (vector 1): prints ascii character in r[0]\
TRAP (vector 2): r[7] = pc, pc = r[0], prints null terminated ascii string\
TRAP (vector 3): r[7] = pc, pc = r[0], gets user inputted string with max length stored in r[1] and stores it sequentially at address in r[0]\
RET: pc = r[7] ex. trap 0\
ex. ret
TRAP (vector 0): halts program
TRAP (vector 1): prints ascii character in r[0]
TRAP (vector 2): r[7] = pc, pc = r[0], prints null terminated ascii string
TRAP (vector 3): r[7] = pc, pc = r[0], gets user inputted string with max length stored in r[1] and stores it sequentially at address in r[0]
ex. trap 0
**** NOTES **** **** NOTES ****
any immediate values in assembly will clamp to be within bounds, e.g. for ADD normal immediate, if you put 60 as the immediate value it will clamp to 15 any immediate values in assembly will clamp to be within bounds, e.g. for ADD normal immediate, if you put 60 as the immediate value it will clamp to 15\
any unused bits in a machine code instruction will be set to 0 any unused bits in a machine code instruction will be set to 0\
strings are NOT packed!!! strings are NOT packed!!!\
pc is *always* incremented at the start of execution, so instructions that change or use pc such as jmp will use the incremented pc as the base pc is *always* incremented at the start of execution, so instructions that change or use pc such as jmp will use the incremented pc as the base\
sext stands for sign extend and not anything else sext stands for sign extend and not anything else\
you MUST include trap 0 to halt the program somewhere or else it'll crash you MUST include trap 0 to halt the program somewhere or else it'll crash\
condition codes are set after instructions with *, so if the result of an instruction with an * is: condition codes are set after instructions with *, so if the result of an instruction with an * is:\
negative -> n bit is set negative -> n bit is set\
zero -> z bit is set zero -> z bit is set\
positive -> p bit is set positive -> p bit is set\