From bc4c57b243eaad8ef054d6ab7de7602b76b22f0d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 3 Nov 2023 21:27:18 +0000 Subject: Use label features and entry points for examples --- examples/factorial.asm | 9 ++++++--- examples/fib.asm | 8 ++++++-- examples/instruction-test.asm | 4 ++++ examples/memory-print.asm | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/factorial.asm b/examples/factorial.asm index 08c3c13..2d4b6f9 100644 --- a/examples/factorial.asm +++ b/examples/factorial.asm @@ -1,7 +1,10 @@ -;;; factorai.asm: A program that generates the factorials of each +;;; factorial.asm: A program that generates the factorials of each ;;; number from 1 to 24 (24!~=UINT64_MAX). Using the registers to ;;; store `n` and `n!`. + ;; Setup entrypoint + global main +main: ;; Setup initial REG[0] = 1 and REG[1] = 1 push.word 1 mov.word 0 @@ -9,7 +12,7 @@ mov.word 1 ;; Print `REG[0]: REG[1]` - ;; Here is the loop back point `#` +loopback: push.byte '\t' print.char push.reg.word 0 @@ -39,5 +42,5 @@ push.reg.word 0 gte.word ;; Jump to `#` - jump.if.byte 4 + jump.if.byte loopback halt diff --git a/examples/fib.asm b/examples/fib.asm index 5542f48..4d61d5c 100644 --- a/examples/fib.asm +++ b/examples/fib.asm @@ -3,6 +3,10 @@ ;;; pairs of fibonacci numbers, we ensure only a finite amount of ;;; memory is necessary for this program to function, unlike a pure ;;; stack version. + + ;; Setup entrypoint + global main +main: ;; Setup initial REG[0] = 1 and REG[1] = 1 push.word 1 mov.word 0 @@ -10,7 +14,7 @@ mov.word 1 ;; Print REG[0] and REG[1] - ;; Here is the loop back point `#` +loopback: push.byte '\t' print.char push.reg.word 0 @@ -41,5 +45,5 @@ push.reg.word 1 gte.word ;; Jump to `#` - jump.if.byte 4 + jump.if.byte loopback halt diff --git a/examples/instruction-test.asm b/examples/instruction-test.asm index 8e8ca2e..bd31c68 100644 --- a/examples/instruction-test.asm +++ b/examples/instruction-test.asm @@ -2,6 +2,10 @@ ;;; order, with proper calling convention. Used to test lexer and ;;; parser but isn't a semantically correct program, but may be run as ;;; first instruction is halt (so program will stop immediately). + + ;; setup entrypoint + global main +main: halt push.byte 1 push.hword 2 diff --git a/examples/memory-print.asm b/examples/memory-print.asm index ed32b7a..9a2bb06 100644 --- a/examples/memory-print.asm +++ b/examples/memory-print.asm @@ -1,5 +1,9 @@ ;;; memory-print: An example program that features a subroutine for ;;; printing a memory buffer, of any length, as characters. + + ;; Setup label for entrypoint + global main +main: ;; Allocate a buffer of 3 characters malloc.byte 3 mov.word 0 -- cgit v1.2.3-13-gbd6f