Compare commits

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