From e618f37cf0be91c4ce7bdb3c02867b452883bcd2 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 8 Nov 2024 17:52:52 +0000 Subject: [PATCH] Print result --- postfix.s | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/postfix.s b/postfix.s index 5da174a..64b16a2 100644 --- a/postfix.s +++ b/postfix.s @@ -106,10 +106,9 @@ dodivide: mov $1,%rdx endword: - ## Go back to start if the terminating character (which is in R8) - ## of the word was a line feed + ## Handle end of line cmp $0x0a, %r8 - je _start + je endline ## Add the word length to RSI and increment until non-space is ## found @@ -124,6 +123,43 @@ spaceloop: mov $0, %rdx jmp wordloop +endline: + mov $buf,%rsi + add $100,%rsi + mov $1,%rcx + + ## Add line feed at end of buffer + movb $0x0a,(%rsi) + + ## Set base and pop value + mov $10,%r8 + pop %rax +formatloop: + dec %rsi + inc %rcx + + ## Divide RAX by ten to get unformatted value (RAX) and current + ## digit value (RDX) + mov $0,%rdx + idiv %r8 + + ## Write character for digit into buffer + add $0x30,%rdx + movb %dl,(%rsi) + + ## Loop if the unformatted value is non-zero + cmp $0,%rax + jne formatloop + + ## Print value + mov $1,%rax + mov $1,%rdi + mov %rcx,%rdx + syscall + + ## Return to top + jmp _start + exit: ## Exit with code 0 mov $60, %rax