examples/fib.asm now terminates on a very large bound
This is using the comparators and a jump-if
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
;;; fib.asm: A program that indefinitely generates the fibonacci
|
;;; fib.asm: A program that generates the fibonacci numbers up to a
|
||||||
;;; numbers. Using the registers to store the pairs of fibonacci
|
;;; very large bound (~UINT64_MAX). Using the registers to store the
|
||||||
;;; numbers, we ensure only a finite memory space is necessary for
|
;;; pairs of fibonacci numbers, we ensure only a finite amount of
|
||||||
;;; this program to function, unlike a pure stack version.
|
;;; memory is necessary for this program to function, unlike a pure
|
||||||
|
;;; stack version.
|
||||||
;; 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
|
||||||
@@ -10,11 +11,19 @@
|
|||||||
|
|
||||||
;; Print REG[0] and REG[1]
|
;; Print REG[0] and REG[1]
|
||||||
;; Here is the loop back point `#`
|
;; Here is the loop back point `#`
|
||||||
|
push.hword 1
|
||||||
|
print.hword
|
||||||
|
push.byte ':'
|
||||||
|
print.char
|
||||||
push.reg.word 0
|
push.reg.word 0
|
||||||
print.word
|
print.word
|
||||||
push.byte '\n'
|
push.byte '\n'
|
||||||
print.char
|
print.char
|
||||||
|
|
||||||
|
push.hword 2
|
||||||
|
print.hword
|
||||||
|
push.byte ':'
|
||||||
|
print.char
|
||||||
push.reg.word 1
|
push.reg.word 1
|
||||||
print.word
|
print.word
|
||||||
push.byte '\n'
|
push.byte '\n'
|
||||||
@@ -32,6 +41,9 @@
|
|||||||
plus.word
|
plus.word
|
||||||
mov.word 1
|
mov.word 1
|
||||||
|
|
||||||
|
push.word 12200160415121876738
|
||||||
|
push.reg.word 1
|
||||||
|
gte.word
|
||||||
;; Jump to `#`
|
;; Jump to `#`
|
||||||
jump.abs 4
|
jump.if.byte 4
|
||||||
halt
|
halt
|
||||||
|
|||||||
Reference in New Issue
Block a user