Split line into words

This commit is contained in:
Camden Dixie O'Brien 2024-11-08 16:06:31 +00:00
parent 2796f62735
commit 4ba2bd48bc

View File

@ -21,6 +21,42 @@ readloop:
cmp $0x0a, %rax
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 with code 0
mov $60, %rax