printf: Add format specifier %p

This commit is contained in:
2025-07-15 16:39:19 +02:00
parent 70ab8b19c3
commit e718e1534b
2 changed files with 23 additions and 2 deletions

View File

@@ -69,6 +69,8 @@ puts:
; %X Unsigned integer, printed as hexadecimal number (uppercase)
; %b Unsigned integer, printed as binary number
; %o Unsigned integer, printed as octal number
; %p Print pointer, but truly alias for %#x -- this printf/udec processes all arguments as qwords so both %x and %p (and other specifiers) will always print full true value.
; That is also why %l/%ll is not supported - it's not needed.
; %s String
; %#{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
@@ -281,6 +283,8 @@ printf:
je .rep_b
cmp byte [rdi + 1], 'o'
je .rep_o
cmp byte [rdi + 1], 'p'
je .rep_p
cmp byte [rdi + 1], 's'
je .rep_s
@@ -329,6 +333,11 @@ printf:
.rep_o:
process_arg 8, 0, utoa
;--- '%p' ---;
.rep_p:
mov r15, 1 ;always force prefix, no matter if %p or %#p was used. Do not override padding though
process_arg 16, 0, utoa
;--- '%s' ---;
.rep_s:
load_arg rsi