diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-09 09:45:22 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-09 09:45:22 +1000 |
| commit | 7f334796e8d0619dc744b1345a7b7b73a27220f9 (patch) | |
| tree | 709c9a7df920d8eb1e779df4f878a25596303f17 /ROMs | |
| parent | d36d51429d604f0ab3b2076c4c05e28ebf9b52c5 (diff) | |
added method calling and for loops
Diffstat (limited to 'ROMs')
| -rw-r--r-- | ROMs/hello_c.asm | 28 | ||||
| -rw-r--r-- | ROMs/hello_c.c | 11 | ||||
| -rw-r--r-- | ROMs/hello_c.q1 | bin | 56 -> 72 bytes |
3 files changed, 23 insertions, 16 deletions
diff --git a/ROMs/hello_c.asm b/ROMs/hello_c.asm index e06d4e0..761f32b 100644 --- a/ROMs/hello_c.asm +++ b/ROMs/hello_c.asm @@ -1,17 +1,23 @@ -_main: - ; comment - mov 5, [$51FF] ; int a = 5 + 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 5, V1 ; right operand + mov [$5201], V1 ; right operand pop V0 ; get left operand back - cmp V0, V1 ; compute equality check - bz LX ; check if condition - not - jmp _end_1 ; if succeeds, continue, else jump to end - mov 99, V0 ; return value + add V0, V1 ; compute addition + mov AX, V0 ; return value ret -_end_1: - mov 0, V0 ; return value + 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 0, V0 ; fallback return 0 ret diff --git a/ROMs/hello_c.c b/ROMs/hello_c.c index 3310b6b..839c12d 100644 --- a/ROMs/hello_c.c +++ b/ROMs/hello_c.c @@ -1,8 +1,9 @@ +int add(int a, int b) +{ + return a + b; +} + int main() { - //comment - int a = 5; - if (a == 5) - return 99; - return 0; + return add(1, 2); }
\ No newline at end of file diff --git a/ROMs/hello_c.q1 b/ROMs/hello_c.q1 Binary files differindex 0ca60e8..ae6e4bb 100644 --- a/ROMs/hello_c.q1 +++ b/ROMs/hello_c.q1 |
