Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SYS_EXIT equ 1 ; Allocation if information for better understanding of what certain numbers do
- SYS_READ equ 3
- SYS_WRITE equ 4
- STDIN equ 0
- STDOUT equ 1
- section .data
- msg1 db "= "
- len1 equ $- msg1
- msg2 db "Inside Add"
- len2 equ $- msg2
- msg3 db "Inside Sub"
- len3 equ $- msg3
- msg4 db "Debug"
- len4 equ $- msg4
- section .bss
- var1 resb 2
- op resb 2
- var2 resb 2
- res resb 2
- section .text
- global _start
- _start:
- CheckOp:
- ;Reads STDIN
- mov eax,3
- mov ebx,0
- mov ecx, var1
- mov edx, 2
- int 80h
- mov al, [var1]
- cmp al, '.' ;will hold as a place stopper for the string loop
- je end
- ;Reads STDIN
- mov eax,3
- mov ebx,0
- mov ecx, op
- mov edx, 2
- int 80h
- ;Reads STDIN
- mov eax,3
- mov ebx,0
- mov ecx, var2
- mov edx, 1
- int 80h
- ;;output
- mov eax,4
- mov ebx,1
- mov ecx, var1
- mov edx, 2
- int 80h
- mov eax,4
- mov ebx,1
- mov ecx, op
- mov edx, 2
- int 80h
- mov eax,4
- mov ebx,1
- mov ecx, var2
- mov edx, 2
- int 80h
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- mov al, [op]
- cmp al,'+' ; if addition, jump to callADD (addition procedure call)
- je callADD
- cmp al,'-'
- je callSUB
- callADD:
- call ADD
- callSUB:
- call SUB
- ADD:
- ;Debug Message
- mov eax,4
- mov ebx,1
- mov ecx, msg2
- mov edx, len2
- int 80h
- ; moving the first number to eax register and second number to ebx
- ; and subtracting ascii '0' to convert it into a decimal number
- mov al, [var1]
- sub al, '0'
- mov bl, [var2]
- sub bl, '0'
- ; add eax and ebx
- add al, bl
- ; add '0' to to convert the sum from decimal to ASCII
- add al, '0'
- ; storing the sum in memory location res
- mov [res], al
- mov eax,4 ;Prints equals sign
- mov ebx,1
- mov ecx, msg1
- mov edx, len1
- int 80h
- mov eax,4 ;Prints answer
- mov ebx,1
- mov ecx, res
- mov edx, 2
- int 80h
- jmp CheckOp
- SUB:
- mov eax,4
- mov ebx,1
- mov ecx, msg3
- mov edx, len3
- int 80h
- ; moving the first number to eax register and second number to ebx
- ; and subtracting ascii '0' to convert it into a decimal number
- mov al, [var1]
- sub bl, '0'
- mov bl, [var2]
- sub bl, '0'
- ; subtract eax and ebx
- sub al, bl
- ; add '0' to to convert the sum from decimal to ASCII
- add al, '0'
- ; storing the sum in memory location res
- mov [res], al
- mov eax,4 ;Prints equals sign
- mov ebx,1
- mov ecx, msg1
- mov edx, len1
- int 80h
- mov eax,4 ;Prints answer
- mov ebx,1
- mov ecx, res
- mov edx, 2
- int 80h
- jmp CheckOp
- ;Output: ;Output Statements
- end:
- mov eax,1
- mov ebx,0
- int 80h;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement