Initial version of atoi

Functions to convert strings to integers in various bases
This commit is contained in:
PleegWat
2026-09-02 21:22:04 +02:00
parent 37d0e556d2
commit e8cf5ae35f
3 changed files with 233 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
mov r1, 1
mov r2, test1
mov r3, test1_end
mov r13, test1_pass
jmp atoi_test
test1_pass:
mov r1, 2
mov r2, test2
mov r3, test2_end
mov r13, test2_pass
jmp atoi_test
test2_pass:
mov r1, 3
mov r2, test3
mov r3, test3_end
mov r13, test3_pass
jmp atoi_test
test3_pass:
mov r1, 4
mov r2, test4
mov r3, test4_end
mov r13, test4_pass
jmp atoi_test
test4_pass:
mov r1, 5
mov r2, test5
mov r3, test5_end
mov r13, test5_pass
jmp atoi_test
test5_pass:
success:
jmp success
; test strint.fn_atoi
; Arguments:
; r1 - test number
; r2 - test data label
; r3 - test end-of-string label
; Result:
; void. Hangs in failure: on failure.
; Clobbers:
; r8 - test number
; r9 - Expected result in r1
; r10 - Expected result in r2
; Notes:
; Depends on fn_atoi not clobbering r8-r10.
atoi_test:
mov r8, r1
load_32 r9, [r2]
add r1, r2, 4
mov r10, r3
push r13
mov r13, atoi_test_ret
jmp stdlib.strint.atoi
atoi_test_ret:
pop r13
cmp r1, r9
jne failure
cmp r2, r10
jne failure
jmp r13
failure:
jmp failure
test1: U32 0 "0"
test1_end: "\0"
test2: U32 1 "1"
test2_end: "\0"
test3: U32 2 "2"
test3_end: "\0"
test4: U32 42 "42"
test4_end: "\0"
test5: U32 67 "67"
test5_end: "lol"
include stdlib