Rather than a pointer to the end of the parseable string, we now store the number of bytes we expect to be parsed. Current code allows for 11 bytes of string data which should suffice for most usecases.
54 lines
1.1 KiB
NASM
54 lines
1.1 KiB
NASM
; test harness for strint.atoi
|
|
; Registers:
|
|
; r8 - test address
|
|
; r9 - expected result
|
|
; r10 - actual length
|
|
; r11 - expected length
|
|
mov r8, tests
|
|
next_test:
|
|
; Set up arguments and run test
|
|
add r1, r8, 5 ; Start of test string
|
|
mov r13, atoi_test_ret
|
|
jmp stdlib.strint.atoi
|
|
atoi_test_ret:
|
|
|
|
; Load reference data
|
|
load_32 r9, [r8] ; Expected result
|
|
sub r10, r2, r8
|
|
sub r10, r10, 5 ; Actual string length
|
|
add r11, r8, 4 ; Address of expected length
|
|
load_8 r11, [r11] ; Expected length
|
|
|
|
; Verify results
|
|
cmp r1, r9
|
|
incorrect_result: jne incorrect_result
|
|
cmp r10, r11
|
|
incorrect_length: jne incorrect_length
|
|
|
|
; Next test
|
|
add r8, r8, 0x10
|
|
cmp r8, end_of_tests
|
|
jl next_test
|
|
|
|
; Done
|
|
success: jmp success
|
|
|
|
|
|
include stdlib
|
|
|
|
|
|
@0x1000
|
|
tests:
|
|
; addr result inlen instr
|
|
@0x1000 U32 0 U8 0 "\0"
|
|
@0x1010 U32 0 U8 1 "0\0"
|
|
@0x1020 U32 1 U8 1 "1\0"
|
|
@0x1030 U32 2 U8 1 "2\0"
|
|
@0x1040 U32 42 U8 2 "42\0"
|
|
@0x1050 U32 67 U8 2 "67lol\0"
|
|
@0x1060 U32 0x69a U8 5 "0x69a\0"
|
|
@0x1070 U32 0o23 U8 3 "0239\0"
|
|
@0x1080 U32 0b1011 U8 6 "0b1011\0"
|
|
@0x1090 U32 0b10001 U8 7 "0b100012\0"
|
|
end_of_tests:
|