Add support for '%%' in printf()
This commit is contained in:
10
console.asm
10
console.asm
@ -46,7 +46,7 @@ puts:
|
||||
leave
|
||||
ret
|
||||
;----- printf(const char* string, ...) -----;
|
||||
; Currently only supports specifiers: %d, %c, %s
|
||||
; Currently only supports specifiers: %d, %c, %s, %%
|
||||
; Return value: Amount of printed characters
|
||||
printf:
|
||||
push rbp
|
||||
@ -71,6 +71,8 @@ printf:
|
||||
push rdi
|
||||
cmp byte [rdi+1], 'd'
|
||||
je .rep_d
|
||||
cmp byte [rdi+1], '%'
|
||||
je .rep_pct
|
||||
cmp byte [rdi+1], 'c'
|
||||
je .rep_c
|
||||
cmp byte [rdi+1], 's'
|
||||
@ -124,6 +126,12 @@ printf:
|
||||
mov rsi, rax
|
||||
jmp .insertLoop
|
||||
|
||||
;--- %% ---;
|
||||
.rep_pct:
|
||||
mov rdi, '%'
|
||||
dec r10 ;r10 is increased at the end, but not needed because '%%' requires no arg
|
||||
jmp .charToStr
|
||||
|
||||
;--- %c ---;
|
||||
.rep_c:
|
||||
cmp r10, 0
|
||||
|
@ -70,7 +70,7 @@ section .rodata
|
||||
msgPuts db NL,NL,"# puts()",NL,EOS
|
||||
msgPuts1 db "puts() test",EOS
|
||||
; printf()
|
||||
testStr db "Testing: %s, %s, %s, %s, %s, %s, %s, %s, %d, %s",NL,EOS
|
||||
testStr db "Testing: %s, %%, %s, %s, %s, %s, %s, %s, %s, %d, %s",NL,EOS
|
||||
tS1 db "one",EOS
|
||||
tS2 db "two",EOS
|
||||
tS3 db "three",EOS
|
||||
|
Reference in New Issue
Block a user