Fri Mar 25, 2011 9:45 am
đây là bài tinh tổng, hiệu, tích của hai số(còn phần tính thương update sau)
hienxau macro s
call clrscr
mov ah,09
mov dx,offset s
int 21h
endm
.model small
.stack 100h
.data
MENU DB 10,13,"Lua chon mot chuc nang:"
DB 13,10,'1. Tinh tong cua hai so:'
DB 13,10,'2. Tinh hieu cua hai so:'
DB 13,10,'3. Tinh tich cua hai so:'
DB 13,10,'4. Tinh thuong cua hai so:'
db 10,13," ESC de thoat.$"
tbnhap1 DB 13,10,'nhap so nguyen thu nhat:$'
tbnhap2 DB 13,10,'nhap so nguyen thu hai :$'
tbtong DB 13,10,'Tong cua hai so la :$'
tbtich DB 13,10,'Tich cua hai so la :$'
tbhieu DB 13,10,'Hieu cua hai so la :$'
tbthuong DB 13,10,'thuong hai so la :$'
tb3 DB 13,10,'5. thuong hai so la :$'
so1 dw 0
so2 dw 0
du dw 0
.code
mov ax,@data
mov ds,ax
laplai:
hienxau menu
mov ah,01
int 21h
cmp al,"1"
je tinhtong
cmp al,"2"
je tinhhieu
cmp al,"3"
je tinhtich
cmp al,"4"
je tinhthuong
cmp al,27
je thoat
jmp laplai
tinhtong:
call nhapso
hienxau tbtong
mov ax,so1
add ax,so2
call xuat
jmp laplai
tinhhieu:
call nhapso
hienxau tbhieu
mov ax,so1
mov bx,so2
sub ax,bx
call xuat
jmp laplai
tinhtich:
call nhapso
hienxau tbtich
mov ax,so1
mov bx,so2
mul bx
call xuat
jmp laplai
tinhthuong:
call nhapso
hienxau tbthuong
mov ax,so1
mov bx,so2
xor dx,dx
div bx
mov du,dx
call xuat
jmp laplai
clrscr proc
mov al,0
int 10h
ret
clrscr endp
thoat:
mov ah,4ch
int 21h
nhapso proc
hienxau tbnhap1
call nhap
mov so1,ax
hienxau tbnhap2
call nhap
mov so2,ax
ret
nhapso endp
;nhap gia tri tu man hinh
nhap proc
xor bx,bx
xor cx,cx
mov ah,8
int 21h
cmp al,'-'
je am
cmp al,'+'
je duong
jmp so
am:
mov cx,1
duong:
mov ah,2
mov dl,al
int 21h
mov ah,8
int 21h
so:
cmp al,'0'
jb nhaplai
cmp al,'9'
ja nhaplai
mov ah,2
mov dl,al
int 21h
and al,0Fh
cbw
mov si,ax
mov ax,10
mul bx
mov bx,si
add bx,ax
nhaplai:
mov ah,8
int 21h
cmp al,13
jnz so
mov ax,bx
or cx,cx
jz ketthuc
neg ax
ketthuc:
ret
nhap endp
; xuat ket qua ra man hinh
xuat proc
or ax,ax
jge tieptheo
push ax
mov ah,2
mov dl,'-'
int 21h
pop ax
neg ax
tieptheo:
xor cx,cx
mov bx,10
lap:
xor dx,dx
div bx
push dx
inc cx
or ax,ax
jnz lap
mov ah,2
xuatkytu:
pop dx
or dl,30h
int 21h
loop xuatkytu
mov ah,08
int 21h
ret
xuat endp
end
hienxau macro s
call clrscr
mov ah,09
mov dx,offset s
int 21h
endm
.model small
.stack 100h
.data
MENU DB 10,13,"Lua chon mot chuc nang:"
DB 13,10,'1. Tinh tong cua hai so:'
DB 13,10,'2. Tinh hieu cua hai so:'
DB 13,10,'3. Tinh tich cua hai so:'
DB 13,10,'4. Tinh thuong cua hai so:'
db 10,13," ESC de thoat.$"
tbnhap1 DB 13,10,'nhap so nguyen thu nhat:$'
tbnhap2 DB 13,10,'nhap so nguyen thu hai :$'
tbtong DB 13,10,'Tong cua hai so la :$'
tbtich DB 13,10,'Tich cua hai so la :$'
tbhieu DB 13,10,'Hieu cua hai so la :$'
tbthuong DB 13,10,'thuong hai so la :$'
tb3 DB 13,10,'5. thuong hai so la :$'
so1 dw 0
so2 dw 0
du dw 0
.code
mov ax,@data
mov ds,ax
laplai:
hienxau menu
mov ah,01
int 21h
cmp al,"1"
je tinhtong
cmp al,"2"
je tinhhieu
cmp al,"3"
je tinhtich
cmp al,"4"
je tinhthuong
cmp al,27
je thoat
jmp laplai
tinhtong:
call nhapso
hienxau tbtong
mov ax,so1
add ax,so2
call xuat
jmp laplai
tinhhieu:
call nhapso
hienxau tbhieu
mov ax,so1
mov bx,so2
sub ax,bx
call xuat
jmp laplai
tinhtich:
call nhapso
hienxau tbtich
mov ax,so1
mov bx,so2
mul bx
call xuat
jmp laplai
tinhthuong:
call nhapso
hienxau tbthuong
mov ax,so1
mov bx,so2
xor dx,dx
div bx
mov du,dx
call xuat
jmp laplai
clrscr proc
mov al,0
int 10h
ret
clrscr endp
thoat:
mov ah,4ch
int 21h
nhapso proc
hienxau tbnhap1
call nhap
mov so1,ax
hienxau tbnhap2
call nhap
mov so2,ax
ret
nhapso endp
;nhap gia tri tu man hinh
nhap proc
xor bx,bx
xor cx,cx
mov ah,8
int 21h
cmp al,'-'
je am
cmp al,'+'
je duong
jmp so
am:
mov cx,1
duong:
mov ah,2
mov dl,al
int 21h
mov ah,8
int 21h
so:
cmp al,'0'
jb nhaplai
cmp al,'9'
ja nhaplai
mov ah,2
mov dl,al
int 21h
and al,0Fh
cbw
mov si,ax
mov ax,10
mul bx
mov bx,si
add bx,ax
nhaplai:
mov ah,8
int 21h
cmp al,13
jnz so
mov ax,bx
or cx,cx
jz ketthuc
neg ax
ketthuc:
ret
nhap endp
; xuat ket qua ra man hinh
xuat proc
or ax,ax
jge tieptheo
push ax
mov ah,2
mov dl,'-'
int 21h
pop ax
neg ax
tieptheo:
xor cx,cx
mov bx,10
lap:
xor dx,dx
div bx
push dx
inc cx
or ax,ax
jnz lap
mov ah,2
xuatkytu:
pop dx
or dl,30h
int 21h
loop xuatkytu
mov ah,08
int 21h
ret
xuat endp
end