Rewrite X2str functions to itoa/utoa ; it was a stupid idea to have seperate functions (=> more maintenance)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
%include "src/constants.asm"
|
||||
|
||||
extern strlen
|
||||
extern dec2str
|
||||
extern udec2str
|
||||
extern hex2str
|
||||
extern bin2str
|
||||
extern itoa
|
||||
extern utoa
|
||||
|
||||
section .rodata
|
||||
mNL db NL
|
||||
@@ -104,17 +102,21 @@ printf:
|
||||
%endmacro
|
||||
|
||||
%macro push_regs 0
|
||||
sub rsp, SIZE_QWORD
|
||||
push rax
|
||||
push rdi
|
||||
push r9
|
||||
push r10
|
||||
push r11
|
||||
%endmacro
|
||||
|
||||
%macro pop_regs 0
|
||||
pop r11
|
||||
pop r10
|
||||
pop r9
|
||||
pop rdi
|
||||
pop rax
|
||||
add rsp, SIZE_QWORD
|
||||
%endmacro
|
||||
|
||||
; entry:
|
||||
@@ -271,44 +273,40 @@ printf:
|
||||
.rep_d:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdx, r13
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
cmp byte [rdi + 1], 'u'
|
||||
je .callUINT2STR
|
||||
je .callUTOA
|
||||
mov rdi, rsi
|
||||
mov rsi, r12
|
||||
call dec2str
|
||||
jmp .loadConvertedStr
|
||||
.callUINT2STR:
|
||||
mov rsi, 10
|
||||
call itoa
|
||||
jmp .pr
|
||||
.callUTOA:
|
||||
mov rdi, rsi
|
||||
mov rsi, r12
|
||||
call udec2str
|
||||
.loadConvertedStr:
|
||||
mov rsi, 10
|
||||
mov r8, 0
|
||||
call utoa
|
||||
.pr:
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
|
||||
;--- '%x' / '%X' ---;
|
||||
.rep_x:
|
||||
push rdi
|
||||
load_arg rcx
|
||||
xor rsi, rsi
|
||||
mov r8, 1
|
||||
cmp byte [rdi + 1], 'X'
|
||||
cmove rsi, r8
|
||||
mov rdi, rcx
|
||||
push rax
|
||||
push rdx
|
||||
push r9
|
||||
push r10
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
call hex2str
|
||||
mov r8, 0
|
||||
cmp byte [rdi + 1], 'x'
|
||||
je .lower
|
||||
mov r8, 1
|
||||
.lower:
|
||||
mov rdi, rsi
|
||||
mov rsi, 16
|
||||
call utoa
|
||||
mov rsi, rax
|
||||
pop r10
|
||||
pop r9
|
||||
pop rdx
|
||||
pop rax
|
||||
pop rdi
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
|
||||
;--- '%b' ---;
|
||||
@@ -316,9 +314,11 @@ printf:
|
||||
load_arg rsi
|
||||
push_regs
|
||||
mov rdi, rsi
|
||||
mov rsi, r12
|
||||
mov rdx, r13
|
||||
call bin2str
|
||||
mov rsi, 2
|
||||
mov rdx, r12
|
||||
mov rcx, r13
|
||||
mov r8, 0
|
||||
call utoa
|
||||
mov rsi, rax
|
||||
pop_regs
|
||||
jmp .insertString
|
||||
|
Reference in New Issue
Block a user