Print result
This commit is contained in:
parent
00ab820c37
commit
e618f37cf0
42
postfix.s
42
postfix.s
@ -106,10 +106,9 @@ dodivide:
|
|||||||
mov $1,%rdx
|
mov $1,%rdx
|
||||||
|
|
||||||
endword:
|
endword:
|
||||||
## Go back to start if the terminating character (which is in R8)
|
## Handle end of line
|
||||||
## of the word was a line feed
|
|
||||||
cmp $0x0a, %r8
|
cmp $0x0a, %r8
|
||||||
je _start
|
je endline
|
||||||
|
|
||||||
## Add the word length to RSI and increment until non-space is
|
## Add the word length to RSI and increment until non-space is
|
||||||
## found
|
## found
|
||||||
@ -124,6 +123,43 @@ spaceloop:
|
|||||||
mov $0, %rdx
|
mov $0, %rdx
|
||||||
jmp wordloop
|
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:
|
||||||
## Exit with code 0
|
## Exit with code 0
|
||||||
mov $60, %rax
|
mov $60, %rax
|
||||||
|
Loading…
x
Reference in New Issue
Block a user