Correctly set padding length when using prefix (fixes #1)

This commit is contained in:
2025-07-17 14:56:35 +02:00
parent 09cf143b2a
commit 1c5ba65f49
2 changed files with 23 additions and 1 deletions

View File

@@ -256,7 +256,6 @@ utoa:
test r15, r15 ;prefix now? (padding with spaces; r15 is zero) test r15, r15 ;prefix now? (padding with spaces; r15 is zero)
jnz .checkPadding jnz .checkPadding
insert_prefix insert_prefix
add r14, 2
.checkPadding: .checkPadding:
; Substract length of converted number from padLen ; Substract length of converted number from padLen
@@ -264,6 +263,13 @@ utoa:
cmp r14, 0 cmp r14, 0
jle .checkPrefix jle .checkPrefix
mov rcx, r14 mov rcx, r14
test r13, r13
jns .addPadding
test r15, r15
jz .addPadding
sub rcx, 2
cmp rcx, 2
jl .checkPrefix
.addPadding: .addPadding:
mov byte [r10], r11b mov byte [r10], r11b
inc r10 inc r10

View File

@@ -103,6 +103,8 @@ section .rodata
printf14Str db "%#b | %#08b | %#x | %#8X | %#o\n",EOS printf14Str db "%#b | %#08b | %#x | %#8X | %#o\n",EOS
printf15 db TAB,"printf(",DQUO,"%p | %#p | %8p | %#8p | %08p | %#08p\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS printf15 db TAB,"printf(",DQUO,"%p | %#p | %8p | %#8p | %08p | %#08p\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS
printf15Str db "%p | %#p | %8p | %#8p | %08p | %#08p\n",EOS printf15Str db "%p | %#p | %8p | %#8p | %08p | %#08p\n",EOS
printf16 db TAB,"printf(",DQUO,"%x | %#10x | %10x | %#10x | %010x | %#010x\n",DQUO,", str5, str5, str5, str5, strBuff1, strBuff1): ",NL,TAB,TAB,EOS
printf16Str db "%x | %#10x | %10x | %#10x | %010x | %#010x\n",EOS
; strlen() ; strlen()
msgStrlen db NL,"TEST strlen()",NL,EOS msgStrlen db NL,"TEST strlen()",NL,EOS
strlen1 db TAB,"strlen(str1): %d",NL,EOS strlen1 db TAB,"strlen(str1): %d",NL,EOS
@@ -411,6 +413,20 @@ _start:
push strBuff1 push strBuff1
call printf call printf
add rsp, SIZE_QWORD * 2 add rsp, SIZE_QWORD * 2
; TEST 16
lea rdi, [rel printf16]
call print
lea rdi, [rel printf16Str]
lea rsi, [rel str5]
lea rdx, [rel str5]
lea rcx, [rel str5]
lea r8, [rel str5]
lea r9, [rel strBuff1]
sub rsp, SIZE_QWORD
push strBuff1
call printf
add rsp, SIZE_QWORD * 2
%endif %endif
;--- ;---