Sunday, 15 December 2013

Addition Subtraction Multiplication Division (Assembly language program)


PROGRAM

.model small
.stack
print macro m
            lea dx,m
            mov ah,09h
            int 21h
endm
read macro
            mov ah,01h
            int 21h
            sub al,30h
endm
display macro n
            mov dl,n
            add dl,30h
            mov ah,02h
            int 21h
endm
input macro
            read
            mov bl,0ah
            mul bl
            mov cl,al
            read
            add al,cl
endm
result macro
            mov ah,00h
            mov bl,0ah
            div bl
            mov bh,ah
            display al
            display bh
endm
.data
           
            a db 0ah,0dh,"Enter the first Number:$"
            b db 0ah,0dh,"Enter the Second Number:$"
            s db 0ah,0dh, "Sum = $"
            n db 0ah,0dh,"Difference = $"
            p db 0ah,0dh,"Product = $"
            q db 0ah,0dh,"Quotient = $"
            r db 0ah,0dh,"Reminder = $"
            s1 db 0ah,0dh, "1. Addition   2. Subtraction     3. Multiplication       4. Division       5. Exit$"
            s2 db 0ah,0dh,"Enter your Choice: $"
            d db ?
            e db ?
.code
            mov ax,@data
            mov ds,ax

l1:        print s1
            print s2
            read
            mov ch,al
            cmp al,05
            je exit
            print a
            input
            mov d,al
            print b
            input
            mov e,al
            cmp ch,01
            je la
            cmp ch,02
            je ls
            cmp ch,03
            je lm
            cmp ch,04
            je ld
la:        print s
            mov al,d
            add al,e
            result
            jmp l1
ls:         print n
            mov al,d
            cmp al,e
            jl l2
            sub al,e
            jmp l3
            l2: mov bl,e
                sub bl,al
                mov al,bl
            l3:result
            jmp l1
lm:       print p
            mov al,d
            mov cl,e
            mul cl
            result
            jmp l1
ld:        print q
            mov al,d
            mov cl,e
            mov ah,00h
            div cl
            mov ch,ah       
            result
            print r
            mov al,ch
            result
            jmp l1
exit:     mov ah,4ch
            int 21h
end

OUTPUT
1. Addition     2. Subtraction  3. Multiplication       4. Division     5. Exit
Enter your Choice: 1
Enter the first Number:52
Enter the Second Number:35
Sum = 87
1. Addition     2. Subtraction  3. Multiplication       4. Division     5. Exit
Enter your Choice: 2
Enter the first Number:56
Enter the Second Number:23
Difference = 33
1. Addition     2. Subtraction  3. Multiplication       4. Division     5. Exit
Enter your Choice: 3
Enter the first Number:24
Enter the Second Number:03
Product = 72
1. Addition     2. Subtraction  3. Multiplication       4. Division     5. Exit
Enter your Choice: 4
Enter the first Number:63
Enter the Second Number:15
Quotient = 04
Reminder = 03
1. Addition     2. Subtraction  3. Multiplication       4. Division     5. Exit
Enter your Choice: 5

1 comment:

  1. hi, can we input do this in just inputting those 2 numbers and it will display all answers?

    ReplyDelete