printf: Macro process_arg to decrease repeated code
This commit is contained in:
@@ -120,6 +120,20 @@ printf:
|
||||
add rsp, SIZE_QWORD
|
||||
%endmacro
|
||||
|
||||
%macro process_arg 3 ;process_arg [base] [upper/lowercase (r8)] [itoa/utoa]
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
mov rsi, %1
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, %2
|
||||
call %3
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
%endmacro
|
||||
|
||||
; entry:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
@@ -275,71 +289,27 @@ printf:
|
||||
|
||||
;--- '%i' / '%d' / '%u' ---;
|
||||
.rep_d:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
cmp byte [rdi + 1], 'u'
|
||||
je .callUTOA
|
||||
mov rdi, rsi
|
||||
mov rsi, 10
|
||||
call itoa
|
||||
jmp .pr
|
||||
.callUTOA:
|
||||
mov rdi, rsi
|
||||
mov rsi, 10
|
||||
mov r8, 0
|
||||
call utoa
|
||||
.pr:
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
je .unsigned
|
||||
process_arg 10, 0, itoa
|
||||
.unsigned:
|
||||
process_arg 10, 0, utoa
|
||||
|
||||
;--- '%x' / '%X' ---;
|
||||
.rep_x:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, 0
|
||||
cmp byte [rdi + 1], 'x'
|
||||
je .lower
|
||||
mov r8, 1
|
||||
process_arg 16, 1, utoa
|
||||
.lower:
|
||||
mov rdi, rsi
|
||||
mov rsi, 16
|
||||
call utoa
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
process_arg 16, 0, utoa
|
||||
|
||||
;--- '%b' ---;
|
||||
.rep_b:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
mov rsi, 2
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, 0
|
||||
call utoa
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
process_arg 2, 0, utoa
|
||||
|
||||
;--- '%o' ---;
|
||||
.rep_o:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
mov rsi, 8
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, 0
|
||||
call utoa
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
process_arg 8, 0, utoa
|
||||
|
||||
;--- '%s' ---;
|
||||
.rep_s:
|
||||
|
Reference in New Issue
Block a user