; Instead of using jump instructions, ; this program uses 'CALL' and 'RET' to use labels as if they were functions. ; This program creates a function for calculating modulus. ; Then it uses that function for modulus to do modulus math on 2 numbers. ; Then it stops the CPU. LOAD r0, 7 ; First number. LOAD r1, 2 ; Second number. LOAD r2, 0 ; The result register. CALL @FnMod ; First Number % Second Number COPY r15, r2 ; Copy the return value into the register we wanna put the result in. JUMP @Exit @FnMod: DIV r0, r1, r2 ; Divide r0 by r1, and store in r2. MUL r2, r1, r2 ; Scale division result by the divide-by number. SUB r0, r2, r0 ; Subtract r2 from r0, and store in r0. COPY r0, r15 ; Copy the value of r0 into r15. (This program's return convention I guess.) RET ; Return to where the 'CALL' instruction was invoked. ; Exit point. This is just to avoid running code under labels by accident. @Exit: HLT ; Stop the CPU.