printf(): Add %c, add test for %c and args on stack
This commit is contained in:
@@ -59,6 +59,7 @@ puts:
|
||||
; Return value: Amount of printed characters
|
||||
; Supported specifiers:
|
||||
; %% Literal percentage sign
|
||||
; %c Single character
|
||||
; %s String
|
||||
; <!> 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
|
||||
@@ -112,6 +113,8 @@ printf:
|
||||
je .wrapup
|
||||
cmp byte [rdi + 1], '%'
|
||||
je .rep_pct
|
||||
cmp byte [rdi + 1], 'c'
|
||||
je .rep_c
|
||||
cmp byte [rdi + 1], 's'
|
||||
je .rep_s
|
||||
|
||||
@@ -125,11 +128,19 @@ printf:
|
||||
|
||||
;--- '%%' ---;
|
||||
.rep_pct:
|
||||
mov [printfBuff+r10], byte '%'
|
||||
add rdi, 2
|
||||
add r10, 1
|
||||
add r11, 1
|
||||
jmp .process
|
||||
mov sil, '%'
|
||||
dec rdx
|
||||
jmp .insertChar
|
||||
|
||||
;--- '%c' ---;
|
||||
.rep_c:
|
||||
cmp rdx, 4
|
||||
ja .c_fromStack
|
||||
mov rsi, [printfArgs + SIZE_QWORD * rdx]
|
||||
jmp .insertChar
|
||||
.c_fromStack:
|
||||
mov rsi, [rbp + RBP_OFFSET_CALLER + ((rdx-5) * SIZE_QWORD)]
|
||||
jmp .insertChar
|
||||
|
||||
;--- '%s' ---;
|
||||
.rep_s:
|
||||
@@ -155,9 +166,18 @@ printf:
|
||||
inc r11
|
||||
jmp .insertString
|
||||
.endInsertString:
|
||||
inc rdx
|
||||
add rdi, 2
|
||||
jmp .process
|
||||
inc rdx
|
||||
add rdi, 2
|
||||
jmp .process
|
||||
|
||||
;--- Insert char to buffer ---;
|
||||
.insertChar:
|
||||
mov [printfBuff + r10], sil
|
||||
add rdi, 2
|
||||
add r10, 1
|
||||
add r11, 1
|
||||
inc rdx
|
||||
jmp .process
|
||||
|
||||
.flushBuffer:
|
||||
push rdi
|
||||
|
Reference in New Issue
Block a user