printf: Add padding support for %d, %i, %u, %x, %X

This commit is contained in:
2025-07-12 16:33:07 +02:00
parent b327248e0c
commit efeded5547
3 changed files with 176 additions and 58 deletions

View File

@@ -71,6 +71,8 @@ puts:
; %X Unsigned integer, printed as hexadecimal number (uppercase)
; %b Unsigned integer, printed as binary number
; %s String
; %N* Pad left, N chars (maximum 64). Supported *: d, i, u, x, X, b
; *0N* Pad left with zeroes, N chars (maximum 64). Supported *: d, i, u, x, X, b
; <!> Unsupported specifiers are printed as-is
; <!> For all specifiers (except %%) an argument is expected. Mismatch between arguments given and specifiers provided will lead to issues
; Used registers:
@@ -236,13 +238,16 @@ printf:
.rep_d:
load_arg rsi
push_regs
mov rdx, r13
cmp byte [rdi + 1], 'u'
je .callUINT2STR
mov rdi, rsi
mov rsi, r12
call dec2str
jmp .loadConvertedStr
.callUINT2STR:
mov rdi, rsi
mov rsi, r12
call udec2str
.loadConvertedStr:
mov rsi, rax
@@ -261,8 +266,12 @@ printf:
push rax
push rdx
push r9
push r10
mov rdx, r12
mov rcx, r13
call hex2str
mov rsi, rax
pop r10
pop r9
pop rdx
pop rax