Split line into words
This commit is contained in:
parent
2796f62735
commit
4ba2bd48bc
36
postfix.s
36
postfix.s
@ -21,6 +21,42 @@ readloop:
|
|||||||
cmp $0x0a, %rax
|
cmp $0x0a, %rax
|
||||||
jne readloop
|
jne readloop
|
||||||
|
|
||||||
|
## Start reading words at start of buffer with zero length
|
||||||
|
mov $buf, %rsi
|
||||||
|
mov $0, %rdx
|
||||||
|
wordloop:
|
||||||
|
## Copy character into R8
|
||||||
|
movzx (%rsi, %rdx), %r8
|
||||||
|
|
||||||
|
## Print the word if the character is a space or a newline
|
||||||
|
cmp $0x20, %r8
|
||||||
|
je doword
|
||||||
|
cmp $0x0a, %r8
|
||||||
|
je doword
|
||||||
|
|
||||||
|
## Increment word length and loop
|
||||||
|
inc %rdx
|
||||||
|
jmp wordloop
|
||||||
|
|
||||||
|
doword:
|
||||||
|
## Go back to start if the terminating character (which is in R8)
|
||||||
|
## of the word was a line feed
|
||||||
|
cmp $0x0a, %r8
|
||||||
|
je _start
|
||||||
|
|
||||||
|
## Add the word length to RSI and increment until non-space is
|
||||||
|
## found
|
||||||
|
add %rdx, %rsi
|
||||||
|
spaceloop:
|
||||||
|
inc %rsi
|
||||||
|
mov (%rsi), %rax
|
||||||
|
cmp $0x20, %rax
|
||||||
|
je spaceloop
|
||||||
|
|
||||||
|
## Zero the word length then return to the word loop.
|
||||||
|
mov $0, %rdx
|
||||||
|
jmp wordloop
|
||||||
|
|
||||||
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