diff --git a/postfix.s b/postfix.s index be2316e..f33339a 100644 --- a/postfix.s +++ b/postfix.s @@ -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