Add operator handling

This commit is contained in:
Camden Dixie O'Brien 2024-11-08 17:23:17 +00:00
parent 9b7ac43643
commit 00ab820c37

View File

@ -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)