Use r13 only instead of r13+r15 (bitmasking)
This commit is contained in:
@@ -91,11 +91,9 @@ puts:
|
||||
; r9* (optional arg) >> Keeps track of where to jump after flushing buffer
|
||||
; r10* Keeps track of current index of printfBuff
|
||||
; r11* Keeps track of total characters (return value)
|
||||
; r12 Padding for numbers (0=nopadding, >0=padding w/ spaces, NOT >0=padding w/ zeroes)
|
||||
; r13 Padding: zeroes (=1) or spaces (=0)
|
||||
; r12 Padding length
|
||||
; r13 Bitmask, 1 = insert specifier yes/no, 2 = use zeroes for padding yes/no
|
||||
; 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
|
||||
@@ -129,7 +127,7 @@ printf:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
test r15, r15
|
||||
test r13, 1
|
||||
jz %%baseNormal
|
||||
mov rsi, ~%1
|
||||
jmp %%args
|
||||
@@ -137,7 +135,13 @@ printf:
|
||||
mov rsi, %1
|
||||
%%args:
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
test r13, 2
|
||||
jz %%padSpaces
|
||||
mov rcx, 1
|
||||
jmp %%movr8 ;nice label name isn't it?
|
||||
%%padSpaces:
|
||||
mov rcx, 0
|
||||
%%movr8:
|
||||
mov r8, %2
|
||||
call %3
|
||||
mov rsi, rax
|
||||
@@ -148,10 +152,10 @@ printf:
|
||||
; entry:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
sub rsp, SIZE_QWORD
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
push r15
|
||||
|
||||
cmp byte [rdi], EOS
|
||||
je .emptyStr
|
||||
@@ -167,7 +171,6 @@ printf:
|
||||
xor r10, r10
|
||||
xor r11, r11
|
||||
xor r14, r14
|
||||
xor r15, r15
|
||||
|
||||
.process:
|
||||
cmp byte [rdi], EOS
|
||||
@@ -218,19 +221,20 @@ printf:
|
||||
je .wrapup
|
||||
cmp byte [rdi + 1], '%'
|
||||
je .rep_pct
|
||||
; Include specifier (r15=1) or not (r15=0)
|
||||
xor r15, r15
|
||||
; Include specifier (r13 bit0=1) or not (bit0=0)
|
||||
xor r13, r13
|
||||
cmp byte [rdi + 1], '#'
|
||||
jne .argGetPadZeroes
|
||||
inc rdi
|
||||
mov r15, 1
|
||||
; Padding: zeroes (r13=1) or spaces (r13=0)
|
||||
bts r13, 0
|
||||
; Padding: zeroes (r13i bit1=1) or spaces (bit1=0)
|
||||
.argGetPadZeroes:
|
||||
xor r13, r13
|
||||
mov r12, 1
|
||||
cmp byte [rdi + 1], '0'
|
||||
jb .noPadding
|
||||
cmove r13, r12
|
||||
ja .padSpaces
|
||||
bts r13, 1
|
||||
.padSpaces:
|
||||
cmp byte [rdi + 1], '9'
|
||||
jg .noPadding
|
||||
xor r12, r12
|
||||
@@ -335,7 +339,7 @@ printf:
|
||||
|
||||
;--- '%p' ---;
|
||||
.rep_p:
|
||||
mov r15, 1 ;always force prefix, no matter if %p or %#p was used. Do not override padding though
|
||||
bts r13, 0 ;always force prefix, no matter if %p or %#p was used. Do not override padding though
|
||||
process_arg 16, 0, utoa
|
||||
|
||||
;--- '%s' ---;
|
||||
@@ -360,7 +364,6 @@ printf:
|
||||
inc r14
|
||||
add rdi, 2
|
||||
xor r12, r12
|
||||
xor r13, r13
|
||||
jmp .process
|
||||
|
||||
;--- Insert char to buffer ---;
|
||||
@@ -370,7 +373,6 @@ printf:
|
||||
add r10, 1
|
||||
add r11, 1
|
||||
xor r12, r12
|
||||
xor r13, r13
|
||||
inc r14
|
||||
jmp .process
|
||||
|
||||
@@ -411,9 +413,9 @@ printf:
|
||||
xor rax, rax
|
||||
|
||||
.quit:
|
||||
pop r15
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
add rsp, SIZE_QWORD
|
||||
leave
|
||||
ret
|
||||
|
Reference in New Issue
Block a user