diff --git a/console.asm b/console.asm index 2a952bd..cb03e84 100644 --- a/console.asm +++ b/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 diff --git a/tests.asm b/tests.asm index 3b66a0b..09d2e61 100644 --- a/tests.asm +++ b/tests.asm @@ -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