diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-01 16:39:07 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-01 16:39:07 +0000 |
commit | 0bab4ec014777aa8e409de93ff7d8d4e8fcf490d (patch) | |
tree | 10947debb9a311084f33a56aedd0071411d6c3e8 | |
parent | b6daa58cab038eb6138b5605dd5a589b793b700d (diff) | |
download | ovm-0bab4ec014777aa8e409de93ff7d8d4e8fcf490d.tar.gz ovm-0bab4ec014777aa8e409de93ff7d8d4e8fcf490d.tar.bz2 ovm-0bab4ec014777aa8e409de93ff7d8d4e8fcf490d.zip |
Made an example translation of fib.c to the custom assembly (fib.asm)
-rw-r--r-- | examples/fib.asm | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/fib.asm b/examples/fib.asm new file mode 100644 index 0000000..004a5c3 --- /dev/null +++ b/examples/fib.asm @@ -0,0 +1,37 @@ +;;; fib.asm: A program that indefinitely generates the fibonacci +;;; numbers. Using the registers to store the pairs of fibonacci +;;; numbers, we ensure only a finite memory space is necessary for +;;; this program to function, unlike a pure stack version. + ;; Setup initial REG[0] = 1 and REG[1] = 1 + push.word 1 + mov.word 0 + push.word 1 + mov.word 1 + + ;; Print REG[0] and REG[1] + ;; Here is the loop back point `#` + push.reg.word 0 + print.word + push.byte '\n' + print.char + + push.reg.word 1 + print.word + push.byte '\n' + print.char + + ;; REG[0] += REG[1] + push.reg.word 0 + push.reg.word 1 + plus.word + mov.word 0 + + ;; REG[1] += REG[0] + push.reg.word 0 + push.reg.word 1 + plus.word + mov.word 1 + + ;; Jump to `#` + jump.abs 4 + halt |