Used more subroutines in fib.asm to make code clearer

Looks way more high level but parses down to a very simple bytecode.
However, because of lack of inline code processing, it relies on the
call stack quite heavily.  With inline labels this would be a much
more compact bytecode.
This commit is contained in:
2023-11-03 21:49:40 +00:00
parent bc4c57b243
commit 32ee84ef70

View File

@@ -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