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