Making Calculutor using assembly program


 Write a program to generate calculutor in assembly program.

 Generate calculutor using assembly programming.

 Write a assembly program to calculutor.

 

Program:-

;calculutor program

print macro msg

push ax

push dx

                mov ah,09h

                mov dx,offset msg

                int 21h

pop dx

pop ax

endm

 

data segment

                first db 13,10,"Enter the 1st number: $"

        second db 13,10,"Enter the 2nd number: $"

        result db 13,10,"Result : $"

                quo db 13,10,"Quotient : $"

        rem db 13,10,"Remainder : $"

                cmsg db 13,10,"Enter your choice : $"

                mmsg db 13,10,"*******MENU********$"

                msg1 db 13,10,"1- To add two numbers$"

        msg2 db 13,10,"2- To subtract two numbers$"

        msg3 db 13,10,"3- To multiply two numbers$"

        msg4 db 13,10,"4- To divide two numbers$"

               

                msg5 db 13,10,"5- Exit$"

 

       

 

                wcmsg db 13,10,"Illegal choice... Choose from the menu!$"

                dname db 20 dup(0)

        nname db 20 dup(0)

data ends

 

code segment

                assume cs:code, ds:data

 

readnum proc

           push ax

                   push bx

           push cx

 

           mov cx,0

           mov bx,10

           mov dx,0

 

r1:

           mov ah,01h

           int 21h

           cmp al,13

           je e1

           sub al,48

           mov cl,al

           mov ax,dx

           mul bx

           add ax,cx

           mov dx,ax

           jmp r1

 

 

e1:

            pop cx

            pop bx

            pop ax

 

ret

readnum endp

 

printnum proc

           push ax

           push bx

           push cx

           push dx

 

           mov cx,0

           mov bx,10

 

r2:

           mov dx,0

           div bx

           add dx,48

           push dx

           add cx,1

           cmp ax,10

           jge r2

           add ax,48

           push ax

           inc cx

 

           mov ah,02h

pnum:

           pop dx

           int 21h

           loop pnum

 

 

          pop dx

          pop cx

          pop bx

          pop ax              

ret

printnum endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

addition proc

           push ax

           push bx

           push cx

           push dx

 

           print first

           call readnum

           mov ax,dx

           print second

           call readnum

           mov bx,dx

           add ax,bx

           print result

           call printnum

 

           pop dx

           pop cx

           pop bx

           pop ax

ret

addition endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

subtraction proc

           push ax

           push bx

           push cx

           push dx

 

           print first

           call readnum

           mov ax,dx

           print second

           call readnum

           mov bx,dx

           sub ax,bx

           print result

           call printnum

 

           pop dx

           pop cx

           pop bx

           pop ax

ret

subtraction endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

multiply proc

           push ax

           push bx

           push cx

           push dx

 

           print first

           call readnum

           mov ax,dx

           print second

           call readnum

           mov bx,dx

           mul bx

           print result

           call printnum

 

           pop dx

           pop cx

           pop bx

           pop ax

ret

multiply endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

divison proc

           push ax

           push bx

           push cx

           push dx

 

           print first

           call readnum

           mov ax,dx

           print second

           call readnum

           mov bx,dx

           mov dx,0

 

           div bx

          

           print quo

           call printnum

 

           mov ax,dx

           print rem

            call printnum

 

           pop dx

           pop cx

           pop bx

           pop ax

ret

divison endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

start:

          mov ax,data

                  mov ds,ax

menu:

         print mmsg

                 print msg1

                 print msg2

         print msg3

                 print msg4

         print msg5

         print cmsg

         

         mov ah,01h

                 int 21h

                  cmp al,'1'

                 je add1

                 cmp al,'2'

                 je sub1

         cmp al,'3'

         je mul1

                 cmp al,'4'

                 je div1

         cmp al,'5'

         je exit

                 print wcmsg

                 jmp menu

         

add1:

  call addition

  jmp menu

 

sub1:

   call subtraction

   jmp menu

 

mul1:

   call multiply

   jmp menu

 

div1:

   call divison

   jmp menu

 

 

exit:

mov ah,4ch

int 21h

code ends

end start

Output:-

No comments:

Post a Comment