diff --git a/postfix.s b/postfix.s index 8ee2c57..5da174a 100644 --- a/postfix.s +++ b/postfix.s @@ -39,6 +39,22 @@ wordloop: jmp wordloop doword: + ## Skip operator checks if word length is greater than 1 + cmp $1,%rdx + jg donum + + ## Check for operators and jump to appropriate procedure + movzx (%rsi),%rax + cmp $0x2b,%rax + je doplus + cmp $0x2d,%rax + je dominus + cmp $0x2a,%rax + je domultiply + cmp $0x2f,%rax + je dodivide + +donum: mov $0, %rax mov $0, %rcx numloop: @@ -56,6 +72,38 @@ numloop: jg numloop push %rax + jmp endword + +doplus: + pop %rbx + pop %rax + add %rbx,%rax + push %rax + jmp endword + +dominus: + pop %rbx + pop %rax + sub %rbx,%rax + push %rax + jmp endword + +domultiply: + pop %rbx + pop %rax + imul %rbx,%rax + push %rax + jmp endword + +dodivide: + pop %rbx + pop %rax + mov $0,%rdx + idiv %rbx + push %rax + + ## Restore RDX + mov $1,%rdx endword: ## Go back to start if the terminating character (which is in R8)