diff options
author | WlodekM <[email protected]> | 2025-03-31 19:27:55 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2025-03-31 19:27:55 +0300 |
commit | ef4e8c20719822eebd6318a878cc37902c2b85a5 (patch) | |
tree | c80cc67921c8b511f5a50ec68834b5b28deb05a1 /code/calc.a |
pc thing
Diffstat (limited to 'code/calc.a')
-rw-r--r-- | code/calc.a | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/code/calc.a b/code/calc.a new file mode 100644 index 0000000..2aa1b02 --- /dev/null +++ b/code/calc.a @@ -0,0 +1,74 @@ +.label len 1 + +jmp start +read_input: + mov a 0 + mov b 0 + mov c 64 + sys + mov b 1 + sub + str c len + ret + +str_to_num: + ; pointer to current character + .label ptr 2 + ld a len + mov b 63 + add + str c ptr + .label mult 3 + mov a 1 + str a mult + .label num 4 + mov a 0 + str a num + .label zero 48 + stm_loop: + ;load char, subtract zero, multiply by 10 + ld b ptr + ldr a b + mov b zero + sub + swp c a + ld b mult + mul + + ; add to num + swp c b + ld a num + add + str c num + + ld a mult + mov b 10 + mul + str c mult + + ; move pointer + ld a ptr + mov b 1 + sub + str c ptr + cmp c 63 + jz stm_loop + ret + +start: + jmr read_input + jmr str_to_num + ld a 4 + str a 8 ; store number 1 to 8 + jmr read_input + jmr str_to_num + ld a 4 ; load number from read + ld b 8 + add + str c 16 ; put our number into 16 + #using printer.a + jmr print_num ; print number at 16 (well not print but stringify) + mov a 1 ; write + mov b 1 ; stdout + mov c 32 ; address + sys ; syscall \ No newline at end of file |