summaryrefslogtreecommitdiff
path: root/ROMs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-09 12:51:08 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-09 12:51:08 +1000
commit78d73c6e3a6e96b750bc4100f754484890ea650b (patch)
tree5c6f8b891513534f4fe722202fcbd3f075536c6e /ROMs
parent7f334796e8d0619dc744b1345a7b7b73a27220f9 (diff)
added lazy function definition
Diffstat (limited to 'ROMs')
-rw-r--r--ROMs/hello_c.asm35
-rw-r--r--ROMs/hello_c.c10
-rw-r--r--ROMs/hello_c.q1bin72 -> 55 bytes
3 files changed, 20 insertions, 25 deletions
diff --git a/ROMs/hello_c.asm b/ROMs/hello_c.asm
index 761f32b..bdb32ff 100644
--- a/ROMs/hello_c.asm
+++ b/ROMs/hello_c.asm
@@ -1,24 +1,21 @@
jmp _main
-_add_int_a__int_b: ; int add(int a, int b)
- pop V0 ; Pop return address to register, to preserve during parameter access
- pop [$51FF] ; param int a
- pop [$5201] ; param int b
- push V0 ; Restore function return address
- push [$51FF] ; left operand
- mov [$5201], V1 ; right operand
- pop V0 ; get left operand back
- add V0, V1 ; compute addition
- mov AX, V0 ; return value
- ret
- mov 0, V0 ; fallback return 0
- ret
-
_main: ; int main()
- push 2 ; arg int a
- push 1 ; arg int b
- call _add_int_a__int_b ; int add(int a, int b)
- mov V0, V0 ; return value
- ret
+ mov 1, [$51FF] ; int x = 1
+ mov 0, [$5201] ; int i = 0
+_body_1:
+ push [$5201] ; left operand
+ mov 10, V1 ; right operand
+ pop V0 ; get left operand back
+ lt V0, V1 ; compute less than check
+ not LX
+ bz
+ jmp _end_2 ; if for condition fails, jump to end
+ mult [$51FF], 2 ; compute multiplication
+ mov AX, [$51FF] ; store back into left param
+ push [$5201] ; i++
+ inc [$5201]
+ pop V0
+_end_2:
mov 0, V0 ; fallback return 0
ret
diff --git a/ROMs/hello_c.c b/ROMs/hello_c.c
index 839c12d..f670952 100644
--- a/ROMs/hello_c.c
+++ b/ROMs/hello_c.c
@@ -1,9 +1,7 @@
-int add(int a, int b)
-{
- return a + b;
-}
-
int main()
{
- return add(1, 2);
+ int x = 1;
+ for (int i = 0; i < 10; i++) {
+ x *= 2;
+ }
} \ No newline at end of file
diff --git a/ROMs/hello_c.q1 b/ROMs/hello_c.q1
index ae6e4bb..1af8388 100644
--- a/ROMs/hello_c.q1
+++ b/ROMs/hello_c.q1
Binary files differ