Answer to Question #226014 in Assembler for sakib

Question #226014

Create a calculator which could do the following operations. Such as

i)          Addition and subtruction of two single digits

ii)                 Other than this it could say whether the single digit is Odd or Even.

iii)         Put 2 single digits and say whether 1st number is greater than 2nd number, less than 2nd number or equal.


1
Expert's answer
2021-08-13T16:12:35-0400
INCLUDE Irvine32.inc
.data
 
EnterN1            BYTE "Enter Number 1: ",0
EnterN2            BYTE "Enter Number 2: ",0

Add_Sub            BYTE "Enter + or -",0
Addition        BYTE "Addition: ",0
Subtruction        BYTE "Subtruction: ",0

OddNumber        BYTE "  Odd", 0
EvenNumber        BYTE "  Even", 0

greater        BYTE "Number1 is greater than Number2 ", 0
less        BYTE "Number1 is less than Number2", 0
equal         BYTE "Number1 is equal to Number2 ", 0  

n1            DWORD ?
n2            DWORD ?

.code
main PROC

    mov   edx, OFFSET EnterN1
    call WriteString    
      
    call Readint            ; Reads N 1
    mov  n1, eax                ; save N1

    mov  edx, OFFSET EnterN2
    call WriteString    
    call Readint            ; Reads N2
    mov  n2,eax                ; save N2

_op:
    call crlf
    mov   edx, OFFSET Add_Sub    
    call WriteString
    call CrLF
    
    call ReadChar            ; wait for input and return char
 
    call WriteChar            ; write char '
    cmp al, '+'                ; is operand == "+" ?
    jz _addition

    cmp al, '-'                ; is operand == "-" ?
    jz _subtruction
    jmp _op

_addition:
    call CrLF
    mov  edx, OFFSET Addition       
    call WriteString    

    mov eax, n1
    add  eax, n2
    call WriteInt            ; write Addition answer
    call CrLF
    jmp _continue

_subtruction:
    call CrLF
    mov  edx, OFFSET Subtruction       
    call WriteString    
    
    mov  eax, n1
    sub  eax, n2
    call WriteInt            ; write Subtruction answer    
    call crlf
    call crlf

_continue:
; is N1 Odd or Even
    mov eax, n1
    call WriteInt    

    and n1, 1
    jz _oddN1
    mov  edx, OFFSET EvenNumber       
    call WriteString    
    jmp _testN2

_oddN1:
    mov  edx, OFFSET OddNumber    
    call WriteString

; is N2 Odd or Even
_testN2:
    call crlf
    mov eax, n2
    call WriteInt    

    and n2, 1
    jz _oddN2
    mov  edx, OFFSET EvenNumber       
    call WriteString    
    jmp _Cmp

_oddN2:
    mov  edx, OFFSET OddNumber    
    call WriteString

_Cmp:
    call crlf
    call crlf
    mov   edx, OFFSET EnterN1
    call WriteString    
      
    call Readint            ; Reads N1
    mov  n1, eax                ; save N1


    mov  edx, OFFSET EnterN2
    call WriteString    
    call Readint            ; Reads N2
    call crlf

    sub  eax, n1
    jz   _equal
    jnc  _less

    mov  edx, OFFSET greater
    call WriteString
    jmp final

_equal:
    mov  edx, OFFSET equal
    call WriteString
    jmp final

_less:
    mov  edx, OFFSET less
    call WriteString

final:
    call crlf
    call CrLF
    Invoke ExitProcess,0    ; exit to operating system
main ENDP
END main




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS