Compare commits

..
1 Commits
Author SHA1 Message Date
PleegWat e8cf5ae35f Initial version of atoi
Functions to convert strings to integers in various bases
2026-09-02 21:22:04 +02:00
2 changed files with 12 additions and 11 deletions
+11 -10
View File
@@ -7,24 +7,25 @@
; Clobbers:
; flags
; r3 - last character read
pub fn_atoi:
; Note: Unless the input is "0", tail-calls into a base-specific specialization.
pub atoi:
load_8 r3, [r1]
cmp r3, 0x30 ; '0'
jne fn_atoi_dec ; No prefix, parse decimal
jne atoi_dec ; No prefix, parse decimal
add r1, r1, 1
load_8 r3, [r1] ; From "boxBOX", or an octal digit
cmp r3, 0x30 ; '0'
jl atoi_badprefix
cmp r3, 0x37 ; '7'
jle fn_atoi_oct
jle atoi_oct
add r1, r1, 1 ; Not octal; 2-byte prefix
and r3, r3, 0x5f ; to uppercase
cmp r3, 0x42 ; 'B'
je fn_atoi_bin
je atoi_bin
cmp r3, 0x4F ; 'O'
je fn_atoi_oct
je atoi_oct
cmp r3, 0x58 ; 'X'
je fn_atoi_hex
je atoi_hex
; not a valid prefix, but we did see a zero
atoi_badprefix:
@@ -43,7 +44,7 @@ jmp r13
; Clobbers:
; flags
; r3 - last character read
pub fn_atoi_dec:
pub atoi_dec:
mov r2, r1
mov r1, 0
atoi_dec_loop:
@@ -69,7 +70,7 @@ jmp atoi_dec_loop
; Clobbers:
; flags
; r3 - last character read
pub fn_atoi_bin:
pub atoi_bin:
mov r2, r1
mov r1, 0
atoi_bin_loop:
@@ -93,7 +94,7 @@ jmp atoi_bin_loop
; Clobbers:
; flags
; r3 - last character read
pub fn_atoi_oct:
pub atoi_oct:
mov r2, r1
mov r1, 0
atoi_oct_loop:
@@ -117,7 +118,7 @@ jmp atoi_oct_loop
; Clobbers:
; flags
; r3 - last character read
pub fn_atoi_hex:
pub atoi_hex:
mov r2, r1
mov r1, 0
atoi_hex_loop:
+1 -1
View File
@@ -56,7 +56,7 @@ add r1, r2, 4
mov r10, r3
push r13
mov r13, atoi_test_ret
jmp stdlib.strint.fn_atoi
jmp stdlib.strint.atoi
atoi_test_ret:
pop r13
cmp r1, r9