diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-29 17:00:39 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-29 17:00:39 +0000 |
commit | fa3ecc00731d3f6045ba2c18aced28cb988d6fa9 (patch) | |
tree | 963bdf9cab634c890641856e418ce7a9f0354318 /examples/factorial.asm | |
parent | 6a34fd2d2ee2159ebc8d1927de55bf9cc2a7dc8d (diff) | |
download | ovm-fa3ecc00731d3f6045ba2c18aced28cb988d6fa9.tar.gz ovm-fa3ecc00731d3f6045ba2c18aced28cb988d6fa9.tar.bz2 ovm-fa3ecc00731d3f6045ba2c18aced28cb988d6fa9.zip |
Easier to read documentation in examples
Diffstat (limited to 'examples/factorial.asm')
-rw-r--r-- | examples/factorial.asm | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/examples/factorial.asm b/examples/factorial.asm index 021360b..42c0785 100644 --- a/examples/factorial.asm +++ b/examples/factorial.asm @@ -1,19 +1,20 @@ ;;; factorial.asm: A program that generates the factorials of each -;;; number from 1 to 24 (24!~=UINT64_MAX). Using the registers to +;;; number from 1 to 22 (22!~=UINT64_MAX). Using the registers to ;;; store `n` and `n!`. + ;; Constants %const(limit) 22 %end ;; Setup entrypoint global main main: - ;; Setup initial REG[0] = 1 and REG[1] = 1 + ;; $I -> W[0] = 1, $J -> W[1] = 1 push.word 1 mov.word 0 push.word 1 mov.word 1 - ;; Print `REG[0]: REG[1]` + ;; Print `$I: $J` loopback: push.byte '\t' print.char @@ -28,21 +29,23 @@ loopback: push.byte '\n' print.char - ;; REG[0] += 1 + ;; $I += 1 push.reg.word 0 push.word 1 plus.word mov.word 0 - ;; REG[1] *= REG[0] + ;; $J *= $I push.reg.word 0 push.reg.word 1 mult.word mov.word 1 + ;; IF $I >= $LIMIT ... push.word $limit push.reg.word 0 gte.word - ;; Jump to `loopback` + ;; THEN jump to `loopback` jump.if.byte loopback + ;; ELSE halt halt |