routine_test.tac (999B)
1 # routine_test - Demonstrates how to jump with `pcr` instructions to return to 2 # the original calling instruction. 3 # load a string on the stack 4 lni 0x0,0xa,0x21,0x65,0x6e,0x6f,0x20,0x67,0x6e,0x69,0x72,0x74,0x73 5 # get the return address and push to stack 6 pcr 7 # jump to the print function 8 jmp print 9 # the print function returns here, and we print a different string 10 lni 0x0,0xa,0x21,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x64,0x6e,0x6f,0x63,0x65,0x73 11 pcr 12 jmp print 13 # spin forever once we're done printing strings 14 complete: jmp complete 15 # expect a string on the stack and our return address at the top of stack 16 print: pop 17 mov GRA GRB 18 sop_and 19 li 252 20 sp GRA 21 # loop until we reach a null byte 22 print_loop: pop 23 cmp GRA GRA 24 jmp print_done 25 sb GRA 26 jmp print_loop 27 # return to sender 28 print_done: mov GRB GRA 29 goto