diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/fib.asm | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/examples/fib.asm b/examples/fib.asm index 4d61d5c..85df000 100644 --- a/examples/fib.asm +++ b/examples/fib.asm @@ -7,6 +7,9 @@ ;; Setup entrypoint global main main: + ;; Setup iterator i + push.word 1 + mov.word 2 ;; Setup initial REG[0] = 1 and REG[1] = 1 push.word 1 mov.word 0 @@ -15,19 +18,7 @@ main: ;; Print REG[0] and REG[1] loopback: - push.byte '\t' - print.char - push.reg.word 0 - print.word - push.byte '\n' - print.char - - push.byte '\t' - print.char - push.reg.word 1 - print.word - push.byte '\n' - print.char + call print_pair ;; REG[0] += REG[1] push.reg.word 0 @@ -47,3 +38,50 @@ loopback: ;; Jump to `#` jump.if.byte loopback halt + +print_pair: + push.byte '\t' + print.char + call print_i + push.byte ':' + print.char + push.byte ' ' + print.char + call print_reg_0 + push.byte '\n' + print.char + call increment_i + push.byte '\t' + print.char + call print_i + push.byte ':' + print.char + push.byte ' ' + print.char + call print_reg_1 + push.byte '\n' + print.char + call increment_i + ret + +increment_i: + push.reg.word 2 + push.word 1 + plus.word + mov.word 2 + ret + +print_i: + push.reg.word 2 + print.word + ret + +print_reg_0: + push.reg.word 0 + print.word + ret + +print_reg_1: + push.reg.word 1 + print.word + ret |