Apply agreed naming conventions

This commit is contained in:
PleegWat
2026-09-06 16:13:40 +02:00
parent 6f7ad3aa4b
commit 304fe54833
3 changed files with 41 additions and 41 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ pub include imath
pub include array pub include array
pub include console pub include console
pub include mem pub include mem
pub include strint pub include string_to_int
; Needs to be last! ; Needs to be last!
pub include LUTs pub include LUTs
+38 -38
View File
@@ -4,7 +4,7 @@
; r3 - Character being parsed ; r3 - Character being parsed
; r4 - Set to -1 if the input is negative ; r4 - Set to -1 if the input is negative
; Convert string to integer ; Convert string to integer (akin to libc atoi(), strotoi())
; Arguments: ; Arguments:
; r1 - Pointer to string ; r1 - Pointer to string
; Result: ; Result:
@@ -15,30 +15,30 @@
; r3 - last character read ; r3 - last character read
; r4 - Negative marker ; r4 - Negative marker
; Note: Unless the input is "0", tail-calls into a base-specific specialization. ; Note: Unless the input is "0", tail-calls into a base-specific specialization.
pub atoi: pub auto:
mov r2, r1 mov r2, r1
mov r1, 0 mov r1, 0
mov r4, 0 mov r4, 0
load_8 r3, [r2] load_8 r3, [r2]
cmp r3, 0x2D ; '-' cmp r3, 0x2D ; '-'
jne atoi_positive jne auto_positive
sub r4, zr, 1 ; Set r4 to -1 sub r4, zr, 1 ; Set r4 to -1
add r2, r2, 1 add r2, r2, 1
atoi_positive: auto_positive:
load_16 r3, [r2] ; 2-byte prefix "0b", "0o", "0x", etc. load_16 r3, [r2] ; 2-byte prefix "0b", "0o", "0x", etc.
or r3, r3, 0x20 ; 2nd char to lower case or r3, r3, 0x20 ; 2nd char to lower case
add r2, r2, 2 add r2, r2, 2
cmp r3, 0x3062 ; "0b" cmp r3, 0x3062 ; "0b"
je atoi_bin_loop je bin_loop
cmp r3, 0x306F ; "0o" cmp r3, 0x306F ; "0o"
je atoi_oct_loop je oct_loop
cmp r3, 0x3078 ; "0x" cmp r3, 0x3078 ; "0x"
je atoi_hex_loop je hex_loop
sub r2, r2, 2 ; no matching prefix, move pointer back sub r2, r2, 2 ; no matching prefix, move pointer back
jmp atoi_dec_loop jmp dec_loop
; Epilogue ; Epilogue
atoi_done: done:
add r1, r1, r4 ; If r4 is -1, negate r1. Else it's 0 and no effect. add r1, r1, r4 ; If r4 is -1, negate r1. Else it's 0 and no effect.
xor r1, r1, r4 xor r1, r1, r4
mov flags, 0 ; No error mov flags, 0 ; No error
@@ -54,27 +54,27 @@ jmp r13
; flags ; flags
; r3 - last character read ; r3 - last character read
; r4 - Negative marker ; r4 - Negative marker
pub atoi_dec: pub dec:
mov r2, r1 mov r2, r1
mov r1, 0 mov r1, 0
mov r4, 0 mov r4, 0
load_8 r3, [r2] load_8 r3, [r2]
cmp r3, 0x2D ; '-' cmp r3, 0x2D ; '-'
jne atoi_dec_positive jne dec_positive
sub r4, zr, 1 ; Set r4 to -1 sub r4, zr, 1 ; Set r4 to -1
add r2, r2, 1 add r2, r2, 1
atoi_dec_loop: dec_loop:
load_8 r3, [r2] load_8 r3, [r2]
atoi_dec_positive: dec_positive:
sub r3, r3, 0x30 ; '0' sub r3, r3, 0x30 ; '0'
cmp r3, 9 cmp r3, 9
ja atoi_done ja done
add r2, r2, 1 add r2, r2, 1
lsl flags, r1, 2 ; Use flags to help multiply by 10 lsl flags, r1, 2 ; Use flags to help multiply by 10
add r1, r1, flags add r1, r1, flags
lsl r1, r1, 1 lsl r1, r1, 1
add r1, r1, r3 add r1, r1, r3
jmp atoi_dec_loop jmp dec_loop
; Convert binary string to integer ; Convert binary string to integer
; Arguments: ; Arguments:
@@ -86,30 +86,30 @@ jmp atoi_dec_loop
; flags ; flags
; r3 - last character read ; r3 - last character read
; r4 - Negative marker ; r4 - Negative marker
pub atoi_bin: pub bin:
mov r2, r1 mov r2, r1
mov r1, 0 mov r1, 0
mov r4, 0 mov r4, 0
load_8 r3, [r2] load_8 r3, [r2]
cmp r3, 0x2D ; '-' cmp r3, 0x2D ; '-'
jne atoi_bin_positive jne bin_positive
sub r4, zr, 1 ; Set r4 to -1 sub r4, zr, 1 ; Set r4 to -1
add r2, r2, 1 add r2, r2, 1
atoi_bin_positive: bin_positive:
load_16 r3, [r2] ; check for prefix load_16 r3, [r2] ; check for prefix
or r3, r3, 0x20 ; 2nd char to lower case or r3, r3, 0x20 ; 2nd char to lower case
cmp r3, 0x3062 ; "0b" cmp r3, 0x3062 ; "0b"
jne atoi_bin_loop jne bin_loop
add r2, r2, 2 add r2, r2, 2
atoi_bin_loop: bin_loop:
load_8 r3, [r2] load_8 r3, [r2]
sub r3, r3, 0x30 ; '0' sub r3, r3, 0x30 ; '0'
cmp r3, 1 cmp r3, 1
ja atoi_done ja done
add r2, r2, 1 add r2, r2, 1
lsl r1, r1, 1 lsl r1, r1, 1
add r1, r1, r3 add r1, r1, r3
jmp atoi_bin_loop jmp bin_loop
; Convert octal string to integer ; Convert octal string to integer
; Arguments: ; Arguments:
@@ -121,30 +121,30 @@ jmp atoi_bin_loop
; flags ; flags
; r3 - last character read ; r3 - last character read
; r4 - Negative marker ; r4 - Negative marker
pub atoi_oct: pub oct:
mov r2, r1 mov r2, r1
mov r1, 0 mov r1, 0
mov r4, 0 mov r4, 0
load_8 r3, [r2] load_8 r3, [r2]
cmp r3, 0x2D ; '-' cmp r3, 0x2D ; '-'
jne atoi_oct_positive jne oct_positive
sub r4, zr, 1 ; Set r4 to -1 sub r4, zr, 1 ; Set r4 to -1
add r2, r2, 1 add r2, r2, 1
atoi_oct_positive: oct_positive:
load_16 r3, [r2] ; check for prefix load_16 r3, [r2] ; check for prefix
or r3, r3, 0x20 ; 2nd char to lower case or r3, r3, 0x20 ; 2nd char to lower case
cmp r3, 0x306F ; "0o" cmp r3, 0x306F ; "0o"
jne atoi_oct_loop jne oct_loop
add r2, r2, 2 add r2, r2, 2
atoi_oct_loop: oct_loop:
load_8 r3, [r2] load_8 r3, [r2]
sub r3, r3, 0x30 ; '0' sub r3, r3, 0x30 ; '0'
cmp r3, 7 cmp r3, 7
ja atoi_done ja done
add r2, r2, 1 add r2, r2, 1
lsl r1, r1, 3 lsl r1, r1, 3
add r1, r1, r3 add r1, r1, r3
jmp atoi_oct_loop jmp oct_loop
; Convert hexadecimal string to integer ; Convert hexadecimal string to integer
; Arguments: ; Arguments:
@@ -156,33 +156,33 @@ jmp atoi_oct_loop
; flags ; flags
; r3 - last character read ; r3 - last character read
; r4 - Negative marker ; r4 - Negative marker
pub atoi_hex: pub hex:
mov r2, r1 mov r2, r1
mov r1, 0 mov r1, 0
mov r4, 0 mov r4, 0
load_8 r3, [r2] load_8 r3, [r2]
cmp r3, 0x2D ; '-' cmp r3, 0x2D ; '-'
jne atoi_hex_positive jne hex_positive
sub r4, zr, 1 ; Set r4 to -1 sub r4, zr, 1 ; Set r4 to -1
add r2, r2, 1 add r2, r2, 1
atoi_hex_positive: hex_positive:
load_16 r3, [r2] ; check for prefix load_16 r3, [r2] ; check for prefix
or r3, r3, 0x20 ; 2nd char to lower case or r3, r3, 0x20 ; 2nd char to lower case
cmp r3, 0x3078 ; "0x" cmp r3, 0x3078 ; "0x"
jne atoi_hex_loop jne hex_loop
add r2, r2, 2 add r2, r2, 2
atoi_hex_loop: hex_loop:
load_8 r3, [r2] load_8 r3, [r2]
sub r3, r3, 0x30 ; '0' sub r3, r3, 0x30 ; '0'
cmp r3, 10 cmp r3, 10
jb atoi_hex_add jb hex_add
sub r3, r3, 0x11 ; 'A' - '0' sub r3, r3, 0x11 ; 'A' - '0'
and r3, r3, 0xdf ; to lower case and r3, r3, 0xdf ; to lower case
cmp r3, 5 ; 0-5: 6 letters cmp r3, 5 ; 0-5: 6 letters
ja atoi_done ja done
add r3, r3, 10 ; Adjust for digits below add r3, r3, 10 ; Adjust for digits below
atoi_hex_add: hex_add:
add r2, r2, 1 add r2, r2, 1
lsl r1, r1, 4 lsl r1, r1, 4
add r1, r1, r3 add r1, r1, r3
jmp atoi_hex_loop jmp hex_loop
@@ -1,4 +1,4 @@
; test harness for strint.atoi ; test harness for string_to_int
; Registers: ; Registers:
; r8 - test address ; r8 - test address
; r9 - expected result ; r9 - expected result
@@ -10,7 +10,7 @@ next_test:
; Set up arguments and run test ; Set up arguments and run test
add r1, r8, 5 ; Start of test string add r1, r8, 5 ; Start of test string
mov r13, atoi_test_ret mov r13, atoi_test_ret
jmp stdlib.strint.atoi jmp stdlib.string_to_int.auto
atoi_test_ret: atoi_test_ret:
; Load reference data ; Load reference data