; --- A Sample Program Demonstrating All Mnemonics --- ; 0x00-0x0F: Memory & Stack nop ; do nothing load R1, 42 ; loadValue: R1 <- 42 (immediate) load R2, @100 ; loadMemory: R2 <- memory[100] load R3, R1 ; loadReg: R3 <- R1 store @1001, R3 ; store: memory[101] <- R3 push 123 ; pushValue: push immediate 123 on stack push R2 ; pushReg: push contents of R2 on stack pop R4 ; pop: pop top of stack -> R4 ; --- 0x10-0x2F: Arithmetic (Integer + Float) --- ; Integer arithmetic add R1, R4 ; add: R1 = R1 + R4 add R4, 7 ; addValue: R4 = R4 + 7 sub R4, R3 ; sub: R4 = R4 - R3 sub R3, 10 ; subValue: R3 = R3 - 10 mul R1, R4 ; mul: R1 = R1 * R4 (32-bit wrap) mul R4, 2 ; mulValue: R4 = R4 * 2 div R1, R3 ; div: R1 = R1 / R3 (integer division) div R3, 2 ; divValue: R3 = R3 / 2 ; Floating-point arithmetic fadd R5, R6 ; fadd: R5 = float(R5) + float(R6) fadd R5, 3.14 ; faddValue: R5 = float(R5) + 3.14 fsub R6, R7 ; fsub: R6 = float(R6) - float(R7) fsub R6, 1.0 ; fsubValue: R6 = float(R6) - 1.0 fmul R5, R6 ; fmul: R5 = float(R5) * float(R6) fmul R5, 2.0 ; fmulValue: R5 = float(R5) * 2.0 fdiv R6, R5 ; fdiv: R6 = float(R6) / float(R5) fdiv R6, 2.0 ; fdivValue: R6 = float(R6) / 2.0 ; --- 0x70-0x7F: Bitwise / Logical --- and R1, R2 ; R1 = R1 & R2 and R1, 0xFF ; R1 = R1 & 0xFF or R2, R3 ; R2 = R2 | R3 or R2, 0x00FF ; R2 = R2 | 0x00FF xor R1, R4 ; R1 = R1 ^ R4 xor R1, 0x1234 ; R1 = R1 ^ 0x1234 not R1 ; R1 = ~R1 ; --- 0xB0-0xBF: Byte-level memory --- loadbyte R7, @2002 ; R7 = memory[202*4] as u8 storebyte @2003, R7 ; memory[203*4] = (R7 & 0xFF) ; --- 0xC00 - Comparisons & Conditional Jumps --- cmp R1, R2 ; set flags based on (R1 - R2) cmp R1, 42 ; set flags based on (R1 - 42) fcmp R5, R6 ; set float flags based on (R5 - R6) fcmp R5, 1.25 ; set float flags based on (R5 - 1.25) jmp @label_unconditional ; Unconditional jump ; Signed conditions label_compare: je @label_equal ; Jump if equal jne @label_notequal ; Jump if not equal jg @label_greater ; Jump if greater jge @label_greaterorequal ; Jump if greater or equal jl @label_less ; Jump if less jle @label_lessorequal ; Jump if less or equal ; Unsigned conditions ja @label_above ; Jump if above (CF=0 & ZF=0) jae @label_aboveorequal ; Jump if above or equal (CF=0) jb @label_below ; Jump if below (CF=1) jbe @label_beloworequal ; Jump if below or equal (CF=1 or ZF=1) ; Other flag conditions jc @label_carry ; Jump if carry = 1 jnc @label_nocarry ; Jump if carry = 0 jo @label_overflow ; Jump if overflow = 1 jno @label_nooverflow ; Jump if overflow = 0 js @label_sign ; Jump if sign = 1 jns @label_nosign ; Jump if sign = 0 jxcz @label_regcxzero ; Jump if CX register is zero (example) ; --- 0xF0 - 0xF2: Call / Return / Syscall --- label_unconditional: call @subroutine ; push IP+1, jump to 'subroutine' syscall ; invoke host IO (R1 often holds syscall code) inspect @200 ; debugging: print memory[200] halt ; A small subroutine: subroutine: ; do something minimal load R8, 999 ; loadValue: R8 <- 999 ret ; --- All condition labels (mostly empty for this demo) --- label_equal: label_notequal: label_greater: label_greaterorequal: label_less: label_lessorequal: label_above: label_aboveorequal: label_below: label_beloworequal: label_carry: label_nocarry: label_overflow: label_nooverflow: label_sign: label_nosign: label_regcxzero: ; return to wherever jumped from ret