diff options
author | WlodekM <[email protected]> | 2025-03-31 19:47:54 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2025-03-31 19:47:54 +0300 |
commit | cccb99226d3951fd9dfe1c4cf1c43126a1309d51 (patch) | |
tree | 518d3e965558ba313f103cee6161cd2b6aedb3b9 /pc-thing/code/calc.a | |
parent | ef4e8c20719822eebd6318a878cc37902c2b85a5 (diff) |
move to pc-thing/
Diffstat (limited to 'pc-thing/code/calc.a')
-rw-r--r-- | pc-thing/code/calc.a | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/pc-thing/code/calc.a b/pc-thing/code/calc.a new file mode 100644 index 0000000..2aa1b02 --- /dev/null +++ b/pc-thing/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 |