X2str(): Fix bug where padding wasn't added for longer (converted) strings

This commit is contained in:
2025-07-14 12:05:00 +02:00
parent 483d9185de
commit e806e50dc2
2 changed files with 25 additions and 33 deletions

View File

@@ -54,8 +54,8 @@ dec2str:
mov r12, 1
.makeString:
sub rsi, rcx
cmp rsi, rcx
jl .noPadding
cmp rsi, 0
jle .noPadding
mov r8, rcx
mov rdi, rsi
xor rsi, rsi
@@ -129,8 +129,8 @@ udec2str:
test rax, rax
jnz .convert
sub rsi, rcx
cmp rsi, rcx
jl .noPadding
cmp rsi, 0
jle .noPadding
mov r8, rcx
mov rdi, rsi
xor rsi, rsi
@@ -206,8 +206,8 @@ hex2str:
test rax, rax
jnz .convert
sub r10, rcx
cmp r10, rcx
jl .noPadding
cmp r10, 0
jle .noPadding
mov r8, rcx
push rsi
mov rdi, r10
@@ -256,15 +256,6 @@ bin2str:
test rdx, rdx
cmovnz r10, r9
lea r9, [rel cnvtBuffRev]
test rdi, rdi
jnz .notZero
lea r9, [rel cnvtBuff]
mov word [r9], '0b'
mov byte [r9 + 2], '0'
mov byte [r9 + 3], EOS
jmp .quit
.notZero:
mov rax, rdi
xor rcx, rcx
.convert:
@@ -278,8 +269,8 @@ bin2str:
test rax, rax
jnz .convert
sub rsi, rcx
cmp rsi, rcx
jl .noPadding
cmp rsi, 0
jle .noPadding
mov r8, rcx
mov rdi, rsi
xor rsi, rsi

View File

@@ -29,21 +29,21 @@ extern hex2str
extern bin2str
section .rodata
TEST_print equ 0
TEST_puts equ 0
TEST_dec2str equ 0 ;includes udec2str
TEST_hex2str equ 0
TEST_bin2str equ 0
TEST_print equ 1
TEST_puts equ 1
TEST_dec2str equ 1 ;includes udec2str
TEST_hex2str equ 1
TEST_bin2str equ 1
TEST_printf equ 1
TEST_strlen equ 0
TEST_strcpy equ 0
TEST_strcat equ 0
TEST_strclr equ 0
TEST_islower equ 0
TEST_isupper equ 0
TEST_tolower equ 0
TEST_toupper equ 0
TEST_strcmp equ 0
TEST_strlen equ 1
TEST_strcpy equ 1
TEST_strcat equ 1
TEST_strclr equ 1
TEST_islower equ 1
TEST_isupper equ 1
TEST_tolower equ 1
TEST_toupper equ 1
TEST_strcmp equ 1
TEST_min equ 0 ;includes minu
TEST_max equ 0 ;includes maxu
@@ -102,8 +102,8 @@ section .rodata
printf10Str db "%x | %8x | %08x",NL,EOS
printf11 db TAB,"printf(",DQUO,"%X | %8X | %08X\n",DQUO,", 0xAB0F, 0xBA0F, 0xAB0F): ",NL,TAB,TAB,EOS
printf11Str db "%X | %8X | %08X",NL,EOS
printf12 db TAB,"rax=0x1234567890ABCDEF",NL,TAB,"printf(",DQUO,"\nRAX = %064b\nEAX = %064b\n AX = %064b\n AH = %56b00000000\n AL = %064b\n",DQUO,", rax, eax, ax, ah, al): ",NL,TAB,TAB,EOS
printf12Str db NL,"RAX = %064b",NL,"EAX = %064b",NL," AX = %064b",NL," AH = %064b",NL," AL = %064b",NL,EOS
printf12 db TAB,"rax=0x1234567890ABCDEF",NL,TAB,"printf(",DQUO,"\nRAX = %064b\nEAX = %64b\n AX = %56b \n AH = %64b\n AL = %64b\n",DQUO,", rax, eax, ax, ah, al): ",NL,TAB,TAB,EOS
printf12Str db NL,"RAX = %064b",NL,"EAX = %64b",NL," AX = %64b",NL," AH = %56b ",NL," AL = %64b",NL,EOS
; strlen()
msgStrlen db NL,"TEST strlen()",NL,EOS
@@ -424,6 +424,7 @@ _start:
mov cx, ax
mov bh, ah
mov r8, rbx
shr r8, 8
mov r9b, al
call printf
%endif