Dump current state of printf() (adding %d support), adds itoa()

This commit is contained in:
2025-06-25 13:07:18 +02:00
parent 1de7731139
commit 4438abda11
3 changed files with 116 additions and 24 deletions

View File

@ -1,11 +1,13 @@
extern NR_write
extern strlen
extern strcat
extern itoa
section .rodata
NL db 0xA
section .bss
printfBuff resb 4096
printfNBuff resb 32
section .text
global print
global puts
@ -64,17 +66,53 @@ printf:
.replaceArg:
cmp byte [rdi+1], 0x0
je .continue
push rdi
cmp byte [rdi+1], 'd'
je .rep_d
cmp byte [rdi+1], 's'
je .rep_s
;--- %d ---;
.rep_d:
;TODO
jmp .continue
cmp r10, 0
je .rep_d_rsi
cmp r10, 1
je .rep_d_rdx
cmp r10, 2
je .rep_d_rcx
cmp r10, 3
je .rep_d_r8
cmp r10, 4
je .rep_d_r9
;get from stack
; rsp + 5*8 : RIP to printf call (+1), PUSH rbp,r12,r13,rdi (+4)
mov rsi, qword [rsp + 5*8 + (r10-5)*8]
jmp .convertInt
.rep_d_rsi:
mov rdi, rsi
jmp .convertInt
.rep_d_rdx:
mov rdi, rdx
jmp .convertInt
.rep_d_rcx:
mov rdi, rcx
jmp .convertInt
.rep_d_r8:
mov rdi, r8
jmp .convertInt
.rep_d_r9:
mov rdi, r9
.convertInt:
lea rsi, [rel printfNBuff]
call itoa
mov rsi, rax
jmp .sinsertLoop
;--- %s ---;
.rep_s:
push rdi
cmp r10, 0
je .sinsertLoop ;nothing to do, rsi already correct
cmp r10, 1