Minor optimizations in printf() (stop using rbx and r13, use smarter checks instead + pop r11 correctly (prevent stack corruption))
This commit is contained in:
16
console.asm
16
console.asm
@ -55,12 +55,9 @@ printf:
|
|||||||
push rbp
|
push rbp
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|
||||||
push rbx ; used to check if error must be sent (reached buff len)
|
|
||||||
push r12 ; used for writing byted to printBuff
|
push r12 ; used for writing byted to printBuff
|
||||||
push r13 ; (also) used for writing bytes to printBuff (why again? gotta check that out - probably not needed, just lost count of register usage at some point)
|
|
||||||
push r14 ; count length of printBuff
|
push r14 ; count length of printBuff
|
||||||
|
|
||||||
xor rbx, rbx
|
|
||||||
xor r10, r10
|
xor r10, r10
|
||||||
xor r14, r14
|
xor r14, r14
|
||||||
lea r11, [rel printfBuff]
|
lea r11, [rel printfBuff]
|
||||||
@ -185,7 +182,6 @@ printf:
|
|||||||
mov [printfNBuff], dil
|
mov [printfNBuff], dil
|
||||||
inc r14
|
inc r14
|
||||||
cmp r14, bufferLength-1
|
cmp r14, bufferLength-1
|
||||||
; Print error to stdout
|
|
||||||
je .finish_L
|
je .finish_L
|
||||||
mov dil, 0
|
mov dil, 0
|
||||||
mov [printfNBuff+1], dil
|
mov [printfNBuff+1], dil
|
||||||
@ -230,8 +226,8 @@ printf:
|
|||||||
je .finish_L
|
je .finish_L
|
||||||
cmp byte [rsi], 0x0
|
cmp byte [rsi], 0x0
|
||||||
je .s0f
|
je .s0f
|
||||||
mov r13b, byte [rsi]
|
mov r12b, byte [rsi]
|
||||||
mov byte [r11], r13b
|
mov byte [r11], r12b
|
||||||
inc r14
|
inc r14
|
||||||
inc rsi
|
inc rsi
|
||||||
inc r11
|
inc r11
|
||||||
@ -255,8 +251,8 @@ printf:
|
|||||||
call print
|
call print
|
||||||
lea rdi, [rel printfBuff]
|
lea rdi, [rel printfBuff]
|
||||||
call strlen
|
call strlen
|
||||||
test rbx, rbx
|
cmp r14, bufferLength-1
|
||||||
jz .final
|
jl .final
|
||||||
|
|
||||||
push r11
|
push r11
|
||||||
mov rax, NR_write
|
mov rax, NR_write
|
||||||
@ -264,13 +260,11 @@ printf:
|
|||||||
lea rsi, [rel ERR_buffLen]
|
lea rsi, [rel ERR_buffLen]
|
||||||
mov rdx, lERR_buffLen
|
mov rdx, lERR_buffLen
|
||||||
syscall
|
syscall
|
||||||
|
pop r11
|
||||||
|
|
||||||
.final:
|
.final:
|
||||||
pop r11
|
|
||||||
pop r14
|
pop r14
|
||||||
pop r13
|
|
||||||
pop r12
|
pop r12
|
||||||
pop rbx
|
|
||||||
|
|
||||||
leave
|
leave
|
||||||
ret
|
ret
|
||||||
|
Reference in New Issue
Block a user