Add operator handling
This commit is contained in:
parent
9b7ac43643
commit
00ab820c37
48
postfix.s
48
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user