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:
@@ -7,6 +7,9 @@
|
|||||||
;; Setup entrypoint
|
;; Setup entrypoint
|
||||||
global main
|
global main
|
||||||
main:
|
main:
|
||||||
|
;; Setup iterator i
|
||||||
|
push.word 1
|
||||||
|
mov.word 2
|
||||||
;; Setup initial REG[0] = 1 and REG[1] = 1
|
;; Setup initial REG[0] = 1 and REG[1] = 1
|
||||||
push.word 1
|
push.word 1
|
||||||
mov.word 0
|
mov.word 0
|
||||||
@@ -15,19 +18,7 @@ main:
|
|||||||
|
|
||||||
;; Print REG[0] and REG[1]
|
;; Print REG[0] and REG[1]
|
||||||
loopback:
|
loopback:
|
||||||
push.byte '\t'
|
call print_pair
|
||||||
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
|
|
||||||
|
|
||||||
;; REG[0] += REG[1]
|
;; REG[0] += REG[1]
|
||||||
push.reg.word 0
|
push.reg.word 0
|
||||||
@@ -47,3 +38,50 @@ loopback:
|
|||||||
;; Jump to `#`
|
;; Jump to `#`
|
||||||
jump.if.byte loopback
|
jump.if.byte loopback
|
||||||
halt
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user