Answer to Question #225552 in Assembler for Kaniz

Question #225552
2. 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.
Put 2 single digits and say whether 1st number is greater than 2nd numbe, less than 2nd number or equal.
1
Expert's answer
2021-08-12T16:25:04-0400
INCLUDE Irvine32.inc
.data
 
EnterN            BYTE "Enter Number 1:  ",0
EnterK            BYTE "Enter Number 2 : ",0

Addition        BYTE "Addition: ",0
Subtruction        BYTE "Subtruction: ",0

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

greater        BYTE "Number1  greater Number2", 0
less        BYTE "Number1  less Number2", 0
equal         BYTE "Number1  equal Number2", 0  

n            DWORD ?
k            DWORD ?

.code
main PROC

    mov   edx, OFFSET EnterN
    call WriteString    
      
    call Readint            ; Reads N
    mov  n, eax                ; save N


    mov  edx, OFFSET EnterK
    call WriteString    
    call Readint            ; Reads K
    mov  k,eax                ; save K
    call crlf

    mov  edx, OFFSET Addition       
    call WriteString    

    add  eax, n
    call WriteInt            ; write Addition answer
    call CrLF

    mov  edx, OFFSET Subtruction       
    call WriteString    
    
    mov  eax, n
    sub  eax, k
    call WriteInt            ; write Subtruction answer    
    call crlf
    call crlf

; is N Odd or Even
    mov eax, n
    call WriteInt    

    and n, 1
    jz _oddN
    mov  edx, OFFSET EvenNumber       
    call WriteString    
    jmp _testK

_oddN:
    mov  edx, OFFSET OddNumber    
    call WriteString

; is K Odd or Even
_testK:
    call crlf
    mov eax, k
    call WriteInt    

    and k, 1
    jz _oddK
    mov  edx, OFFSET EvenNumber       
    call WriteString    
    jmp _testCmp

_oddK:
    mov  edx, OFFSET OddNumber    
    call WriteString


_testCmp:
    call crlf
    call crlf
    mov   edx, OFFSET EnterN
    call WriteString    
      
    call Readint            ; Reads N
    mov  n, eax                ; save N


    mov  edx, OFFSET EnterK
    call WriteString    
    call Readint            ; Reads K
    call crlf

    sub  eax, n
    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
    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