Jumps |
Jumps control the flow through a program. Without them a program could only run from top to bottom. This would be useless. Nano has three basic jump opcodes. You know already one: "jmp_l". jmp label; jumps to label jsr label; jumps to subroutine label rts; return from subroutine jmp_l L, label; jumps to the label, if "L" is true (1) jsr_l L, label; jumps to subroutine, if "L" ist true (1)To speed up loops, I combined two opcodes into one: eq_jmp_l L1, L2, label; jumps to the label, if "L1" is equal "L2" neq_jmp_l L1, L2, label; not equal gr_jmp_l L1, L2, label; greater ls_jmp_l L1, L2, label; less greq_jmp_l L1, L2, label; greater or equal lseq_jmp_l L1, L2, label; less or equal eq_jsr_l L1, L2, label; jumps to subroutine, if "L1" is equal "L2" neq_jsr_l L1, L2, label; see above! gr_jsr_l L1, L2, label; ls_jsr_l L1, L2, label; greq_jsr_l L1, L2, label; lseq_jsr_l L1, L2, label;See also: Loops The following example shows how to use the "jsr" opcode: mul.na 1| push_i 33, L0; 2| push_i 17, L1; 3| 4| jsr multiply; jump to line "11" 5| print_l L2; 6| push_i 1, L3; 7| print_n L3; 8| push_i 0, L3; 9| exit L3; 10| 11| lab multiply; 12| mul_l L0, L1, L2; 13| rts; jump back to line "5"Prev: Loops | Next: Arrays |