From 3510139c2560cf3dddfdc79117b81eaa069f3cbe Mon Sep 17 00:00:00 2001 From: Kwarde Date: Sun, 20 Jul 2025 11:41:20 +0200 Subject: [PATCH] Add tests for atoi() --- src/tests.asm | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/tests.asm b/src/tests.asm index 09c04a6..ca5216c 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -25,6 +25,7 @@ extern strcmp ; convert.asm extern itoa extern utoa +extern atoi section .rodata TEST_print equ 1 @@ -40,9 +41,10 @@ section .rodata TEST_tolower equ 1 TEST_toupper equ 1 TEST_strcmp equ 1 - TEST_min equ 0 ;includes minu - TEST_max equ 0 ;includes maxu + TEST_min equ 1 ;includes minu + TEST_max equ 1 ;includes maxu TEST_clamp equ 1 ;includes clampu + TEST_atoi equ 1 str1 db "Hello, world!",EOS str2 db "Hello, World!",EOS @@ -202,6 +204,20 @@ section .rodata clampuArg2 equ MAX_UINT32 clampu1 db TAB,"clampu(MAX_UINT64, clampArg1, clampArg2): %d",NL,EOS clampu2 db TAB,"clampu(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS + + ; atoi() + msgAtoi db NL,"TEST atoi()",NL,EOS + atoiOutput db TAB,"%s = %d",NL,EOS + atoi1 db "1234567890",EOS + atoi2 db "0xFFFFFFFF",EOS ;4 294 967 295 + atoi3 db "0o776655",EOS ;261 549 + atoi4 db "0b11001001",EOS ;201 + atoi5 db "-0000001",EOS ;-1 + atoi6 db "-1690000000004",EOS + atoi7 db "0x0962ABCDEF",EOS ;40 310 132 207 + atoi8 db "0x0962GBCDEF",EOS ;0 + atoi9 db "0o77865",EOS ;0 + atoi10 db "0b102001",EOS;0 section .data section .bss @@ -1064,6 +1080,33 @@ _start: call printf %endif +;--- +;--- atoi() +;--- +%if TEST_atoi + lea rdi, [rel msgAtoi] + call print + %macro testatoi 1 + lea rdi, [rel %1] + call atoi + lea rdi, [rel atoiOutput] + lea rsi, [rel %1] + mov rdx, rax + call printf + %endmacro + + testatoi atoi1 + testatoi atoi2 + testatoi atoi3 + testatoi atoi4 + testatoi atoi5 + testatoi atoi6 + testatoi atoi7 + testatoi atoi8 + testatoi atoi9 + testatoi atoi10 +%endif + ;--- ;--- exit() ;---