Fix issue in printf() with %d --needed to push+pop several registers before/after itoa() call
This commit is contained in:
14
console.asm
14
console.asm
@ -86,8 +86,7 @@ printf:
|
|||||||
je .rep_d_r9
|
je .rep_d_r9
|
||||||
|
|
||||||
;get from stack
|
;get from stack
|
||||||
; rsp + 5*8 : RIP to printf call (+1), PUSH rbp,r12,r13,rdi (+4)
|
mov rsi, qword [rbp + 16 + (r10-5)*8]
|
||||||
mov rsi, qword [rsp + 5*8 + (r10-5)*8]
|
|
||||||
jmp .convertInt
|
jmp .convertInt
|
||||||
|
|
||||||
.rep_d_rsi:
|
.rep_d_rsi:
|
||||||
@ -107,7 +106,15 @@ printf:
|
|||||||
|
|
||||||
.convertInt:
|
.convertInt:
|
||||||
lea rsi, [rel printfNBuff]
|
lea rsi, [rel printfNBuff]
|
||||||
|
push rcx
|
||||||
|
push rdx
|
||||||
|
push r8
|
||||||
|
push r10
|
||||||
call itoa
|
call itoa
|
||||||
|
pop r10
|
||||||
|
pop r8
|
||||||
|
pop rdx
|
||||||
|
pop rcx
|
||||||
mov rsi, rax
|
mov rsi, rax
|
||||||
jmp .sinsertLoop
|
jmp .sinsertLoop
|
||||||
|
|
||||||
@ -125,8 +132,7 @@ printf:
|
|||||||
je .rep_s_r9
|
je .rep_s_r9
|
||||||
|
|
||||||
;get from stack
|
;get from stack
|
||||||
; rsp + 5*8 : RIP to printf call (+1), PUSH rbp,r12,r13,rdi (+4)
|
mov rsi, qword [rbp + 16 + (r10-5)*8]
|
||||||
mov rsi, qword [rsp + 5*8 + (r10-5)*8]
|
|
||||||
jmp .sinsertLoop
|
jmp .sinsertLoop
|
||||||
|
|
||||||
.rep_s_rdx:
|
.rep_s_rdx:
|
||||||
|
5
core.asm
5
core.asm
@ -160,12 +160,17 @@ itoa:
|
|||||||
inc rcx
|
inc rcx
|
||||||
test rax, rax
|
test rax, rax
|
||||||
jnz .convert
|
jnz .convert
|
||||||
|
test rbx, rbx
|
||||||
|
jz .toString
|
||||||
|
push byte '-'
|
||||||
|
inc rcx
|
||||||
|
|
||||||
.toString:
|
.toString:
|
||||||
pop rdx
|
pop rdx
|
||||||
mov byte [rsi], dl
|
mov byte [rsi], dl
|
||||||
inc rsi
|
inc rsi
|
||||||
loop .toString
|
loop .toString
|
||||||
|
mov byte [rsi], 0
|
||||||
|
|
||||||
.quit:
|
.quit:
|
||||||
pop rsi
|
pop rsi
|
||||||
|
@ -49,6 +49,7 @@ section .rodata
|
|||||||
TEST_toupper equ 1
|
TEST_toupper equ 1
|
||||||
TEST_strcmp equ 1
|
TEST_strcmp equ 1
|
||||||
TEST_file1 equ 1
|
TEST_file1 equ 1
|
||||||
|
;TEST_itoa equ 0 ; not included in these tests; printf() calls itoa for %d specifiers
|
||||||
|
|
||||||
num1 dq 69
|
num1 dq 69
|
||||||
num2 dq 0xFFFFFF
|
num2 dq 0xFFFFFF
|
||||||
|
Reference in New Issue
Block a user