Monday, August 2, 2010

Addition, Subtraction , Multiplication and Division (more than one digit , no decimals)

Sample Output:



Code:


msga db “Enter no 1: $” msgb db 13,10,”Enter no 2: $” msgc db 13,10,”Enter operation[A,S,M,D]: $” msgd db 13,10,”Result: $” msge db “-$”

ends

stack segment dw 128 dup(0)ends

code segmentstart:

mov ax, data mov ds, ax mov es, ax

lea dx, msga mov ah, 9 int 21h

mov ah,1 int 21h

sub al,30h push ax

lea dx, msgb mov ah, 9 int 21h

mov ah,1 int 21h

sub al,30h push ax

lea dx, msgc mov ah, 9 int 21h

mov ah,1 int 21h

mov cl,al

lea dx, msgd mov ah, 9 int 21h

pop

bx

pop ax

cmp cl,’A’ je a jne s1

s1:cmp cl,’S’ je s jne m1

m1:cmp cl,’M’ je m jne d1

d1:cmp cl,’D’ je d jne z

a: mov ah,0 add al,bl call print_ax

jmp z

s: mov ah,0 cmp al,bl ja sa jb sb

sa: sub al,bl jmp sc

sb: sub bl,al

lea dx,msge mov ah,09h int 21h

mov al,bl mov ah,0

sc: call print_ax

jmp z

m: mov ah,0 mov bh,0 mul bx call print_ax

jmp z

d: mov ah,al mov bh,bl mov dl,0 div bx call print_ax

z: mov ax, 4c00h int 21h

ends

print_ax proccmp ax, 0jne print_ax_r push ax

mov al, ‘0′

mov ah, 0eh int 10h pop ax ret print_ax_r: pusha mov dx, 0 cmp ax, 0 je pn_done mov bx, 10 div bx call print_ax_r mov ax, dx add al, 30h mov ah, 0eh int 10h jmp pn_donepn_done: popa ret endp

No comments:

Post a Comment