From 61a1cb50d1c02b4761a1b6087b39514e58ba42ad Mon Sep 17 00:00:00 2001 From: Kwarde Date: Wed, 25 Jun 2025 21:57:01 +0200 Subject: [PATCH] printf() optimization: Use syscall and mov r14 to rax rather than calling print and strlen -- r14 used to contain wrong length: mistakenly increased r14 (and performed checks) for printfNBuff --- console.asm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/console.asm b/console.asm index 3f43fdb..667f3c5 100644 --- a/console.asm +++ b/console.asm @@ -155,14 +155,8 @@ printf: .charToStr: mov [printfNBuff], dil - inc r14 - cmp r14, bufferLength-1 - je .finish mov dil, 0 mov [printfNBuff+1], dil - inc r14 - cmp r14, bufferLength-1 - je .finish lea rsi, [rel printfNBuff] jmp .insertLoop @@ -210,10 +204,12 @@ printf: .finish: mov byte [r11], 0x0 - lea rdi, [rel printfBuff] - call print - lea rdi, [rel printfBuff] - call strlen + mov rax, NR_write + mov rdi, 1 + lea rsi, [rel printfBuff] + mov rdx, r14 + syscall + mov rax, r14 cmp r14, bufferLength-1 jl .final