Allow printing prefixes for %x,%X,%b and %o (pass ~base to udec)
This commit is contained in:
@@ -70,8 +70,9 @@ puts:
|
||||
; %b Unsigned integer, printed as binary number
|
||||
; %o Unsigned integer, printed as octal number
|
||||
; %s String
|
||||
; %N* Pad left, N chars (maximum 64). Supported specifiers: d, i, u, x, X, b, o
|
||||
; *0N* Pad left with zeroes, N chars (maximum 64). Supported specifiers: d, i, u, x, X, b, o
|
||||
; %#{x} Use prefix for printed number (non-decimal). Supported specifiers: x, X, b, o. Works in combination with width specifier (see below)
|
||||
; %[#]n* Pad left, n chars (maximum 64). Supported specifiers: d, i, u, x, X, b, o
|
||||
; *[#]0n* Pad left with zeroes, n chars (maximum 64). Supported specifiers: d, i, u, x, X, b, o
|
||||
; <!> 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
|
||||
;
|
||||
@@ -91,6 +92,8 @@ puts:
|
||||
; r12 Padding for numbers (0=nopadding, >0=padding w/ spaces, NOT >0=padding w/ zeroes)
|
||||
; r13 Padding: zeroes (=1) or spaces (=0)
|
||||
; r14 Keeps track of amount of processed format specifiers
|
||||
; r15 Include prefix for specifiers (1=yes, 0=no)
|
||||
;<!> TODO: Keep r13 and r15 in one register (use bitmasking to determine whether to pad with zeroes or spaces and whether to include prefix)
|
||||
printf:
|
||||
%macro load_arg 1
|
||||
cmp r14, 4
|
||||
@@ -124,7 +127,13 @@ printf:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
test r15, r15
|
||||
jz %%baseNormal
|
||||
mov rsi, ~%1
|
||||
jmp %%args
|
||||
%%baseNormal:
|
||||
mov rsi, %1
|
||||
%%args:
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, %2
|
||||
@@ -140,7 +149,7 @@ printf:
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
sub rsp, SIZE_QWORD
|
||||
push r15
|
||||
|
||||
cmp byte [rdi], EOS
|
||||
je .emptyStr
|
||||
@@ -156,6 +165,7 @@ printf:
|
||||
xor r10, r10
|
||||
xor r11, r11
|
||||
xor r14, r14
|
||||
xor r15, r15
|
||||
|
||||
.process:
|
||||
cmp byte [rdi], EOS
|
||||
@@ -206,6 +216,14 @@ printf:
|
||||
je .wrapup
|
||||
cmp byte [rdi + 1], '%'
|
||||
je .rep_pct
|
||||
; Include specifier (r15=1) or not (r15=0)
|
||||
xor r15, r15
|
||||
cmp byte [rdi + 1], '#'
|
||||
jne .argGetPadZeroes
|
||||
inc rdi
|
||||
mov r15, 1
|
||||
; Padding: zeroes (r13=1) or spaces (r13=0)
|
||||
.argGetPadZeroes:
|
||||
xor r13, r13
|
||||
mov r12, 1
|
||||
cmp byte [rdi + 1], '0'
|
||||
@@ -384,7 +402,7 @@ printf:
|
||||
xor rax, rax
|
||||
|
||||
.quit:
|
||||
add rsp, SIZE_QWORD
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
|
Reference in New Issue
Block a user