printf: Add format specifier %p
This commit is contained in:
@@ -69,6 +69,8 @@ puts:
|
|||||||
; %X Unsigned integer, printed as hexadecimal number (uppercase)
|
; %X Unsigned integer, printed as hexadecimal number (uppercase)
|
||||||
; %b Unsigned integer, printed as binary number
|
; %b Unsigned integer, printed as binary number
|
||||||
; %o Unsigned integer, printed as octal 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
|
; %s String
|
||||||
; %#{x} Use prefix for printed number (non-decimal). Supported specifiers: x, X, b, o. Works in combination with width specifier (see below)
|
; %#{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
|
; %[#]n* Pad left, n chars (maximum 64). Supported specifiers: d, i, u, x, X, b, o
|
||||||
@@ -281,6 +283,8 @@ printf:
|
|||||||
je .rep_b
|
je .rep_b
|
||||||
cmp byte [rdi + 1], 'o'
|
cmp byte [rdi + 1], 'o'
|
||||||
je .rep_o
|
je .rep_o
|
||||||
|
cmp byte [rdi + 1], 'p'
|
||||||
|
je .rep_p
|
||||||
cmp byte [rdi + 1], 's'
|
cmp byte [rdi + 1], 's'
|
||||||
je .rep_s
|
je .rep_s
|
||||||
|
|
||||||
@@ -329,6 +333,11 @@ printf:
|
|||||||
.rep_o:
|
.rep_o:
|
||||||
process_arg 8, 0, utoa
|
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' ---;
|
;--- '%s' ---;
|
||||||
.rep_s:
|
.rep_s:
|
||||||
load_arg rsi
|
load_arg rsi
|
||||||
|
@@ -99,9 +99,10 @@ section .rodata
|
|||||||
printf12Str db "\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",EOS
|
printf12Str db "\nRAX\t%064b\nEAX\t\t\t\t\t%032b\n AX\t\t\t\t\t\t\t%016b\n AH\t\t\t\t\t\t\t%08b\t\n AL\t\t\t\t\t\t\t\t%08b\n",EOS
|
||||||
printf13 db TAB,"printf(",DQUO,"%o | %8o | %08o\n",DQUO,", 1500, 1500, 1500): ",NL,TAB,TAB,EOS
|
printf13 db TAB,"printf(",DQUO,"%o | %8o | %08o\n",DQUO,", 1500, 1500, 1500): ",NL,TAB,TAB,EOS
|
||||||
printf13Str db "%o | %8o | %08o\n",EOS
|
printf13Str db "%o | %8o | %08o\n",EOS
|
||||||
printf14 db TAB,"printf(",DQUO,"%#b | %#08b | %#x | %#8X\n | %#o",DQUO,", 8, 8, 0xABCDEF, 0x12345678, 15): ",NL,TAB,TAB,EOS
|
printf14 db TAB,"printf(",DQUO,"%#b | %#08b | %#x | %#8X | %#o\n",DQUO,", 8, 8, 0xABCDEF, 0x12345678, 15): ",NL,TAB,TAB,EOS
|
||||||
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 | %08p | %#08p\n",DQUO,", 0xabc, 0xabc, 0xabc, 0xabc, 0xabc): ",NL,TAB,TAB,EOS
|
||||||
|
printf15Str db "%p | %#p | %8p | %08p | %#08p\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
|
||||||
@@ -396,6 +397,17 @@ _start:
|
|||||||
mov r8, 0x12345678
|
mov r8, 0x12345678
|
||||||
mov r9, 15
|
mov r9, 15
|
||||||
call printf
|
call printf
|
||||||
|
|
||||||
|
; TEST 15
|
||||||
|
lea rdi, [rel printf15]
|
||||||
|
call print
|
||||||
|
lea rdi, [rel printf15Str]
|
||||||
|
mov rsi, 0xabc
|
||||||
|
mov rdx, 0xabc
|
||||||
|
mov rcx, 0xabc
|
||||||
|
mov r8, 0xabc
|
||||||
|
mov r9, 0xabc
|
||||||
|
call printf
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
;---
|
;---
|
||||||
|
Reference in New Issue
Block a user