35baiASM-Full
;bai1: thuc hien nhap 1 ky tu so va hien thi ky tu vua nhap
;phamtuan_hp89
.model small
.data
kt db 0
tenct db 10,13,'Nhap 1 ky tu, neu la ky tu so -> in ra man hinh, ko la ky tu so -> nhap lai:$'
pkey db 10,13,' press any key to exit ... $'
tb1 db 10,13,'Nhap 1 ky tu so:$'
tb2 db 10,13,'So vua nhap:$'
tb3 db 10,13,'ko phai ky tu so, nhap lai:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
lea dx,tenct
mov ah,9
int 21h
lea dx,tb1
mov ah,9
int 21h
;nhap ky tu
nhap:
mov ah,1
int 21h
cmp al,'0'
jb nhaplai ;nhay neu nho hon
cmp al,'9'
ja nhaplai ;nhay neu lon hon
;hien thi ky tu vua nhap ra nam hinh
mov kt,al
lea dx,tb2
mov ah,9
int 21h
mov dl,kt
mov ah,2
int 21h
jmp exit
nhaplai:
lea dx,tb3
mov ah,9
int 21h
jmp nhap
exit:
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;bai 2: chong trinh thuc hien nhap vao tu ban phim 2 ky tu, 1 la ky tu so, 1 la chu in thuong
;phamtuan_hp89
.model small
.data
kt1 db 0
kt2 db 0
tenct db 10,13,'chong trinh thuc hien nhap vao tu ban phim 2 ky tu, 1 la ky tu so, 1 la chu in thuong$'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap 2 ky tu:$'
tb2 db 10,13,'2 ky tu vua nhap:$'
tb3 db 10,13,'Nhap sai, nhap lai:$'
tb4 db 10,13,'Nhap dung roai$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
;hien thong bao 1
lea dx,tb1
mov ah,9
int 21h
;nhap ky tu
nhap:
mov ah,1
int 21h
mov kt1,al ;gan kt tu vua nhap vao bien kt1
mov ah,1
int 21h
mov kt2,al ;gan ky tu thu 2 vao kt2
docenter: ;doc phim enter sau khi nhap 2 ky tu
int 21h
cmp al,13
je endenter
jmp docenter
endenter: ;end doc enter
;hien thong bao 2
lea dx,tb2
mov ah,9
int 21h
;in 2 ky tu vua nhap ra man hinh
mov ah,2
mov dl,kt1
int 21h
mov dl,kt2
int 21h
;kiem tra kt1:
cmp kt1,'0'
jae kt19 ;nhap neu lon hon or bang
kt19:
cmp kt1,'9'
jbe kt2chu ;nhay neu nho hon or bang
cmp kt1,'a'
jae kt1z
kt1z:
cmp kt1,'z'
jbe kt2so
jmp nhaplai
kt2chu:
cmp kt2,'a'
jb nhaplai
cmp kt2,'z'
ja nhaplai
jmp endnhap
kt2so:
cmp kt2,'0'
jb nhaplai
cmp kt2,'9'
ja nhaplai
jmp endnhap
nhaplai:
lea dx,tb3
mov ah,9
int 21h
jmp nhap
endnhap:
lea dx,tb4
mov ah,9
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 3: chong trinh thuc hien nhap vao 2 so < 10, tim so lon hon
; thuat toan:
;nhap 2 ky tu tu ban phim, kiem tra co trong khoan '0' -> '9' ko
;cmp kt1,kt2, kt1>kt2 -> nhay den doan code hien kt1, else nhay den doan code hien kt2
;ko la so -> nhap lai
; ky tu ma ASCII
; 0 48
; 9 57
; a 97
; z 122
.model small
.data
s1 db 0
s2 db 0
tenct db 10,13,'nhap 2 so, tim so lon hon$'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap so thu 1:$'
tb2 db 10,13,'Nhap so thu 2:$'
tb3 db 10,13,'Nhap sai, nhap lai:$'
tb4 db 10,13,'So lon nhat:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
;nhap so thu 1
nhap1:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov s1,al
docenter:
int 21h
cmp al,13
je endenter
jmp docenter
endenter:
cmp s1,'0'
jb nhap1
cmp s1,'9'
ja nhap1
;in so thu nhat
mov dl,10 ;in
mov ah,2 ; ra
int 21h ; mot
mov dl,13 ; dong
mov ah,2 ; trong'
int 21h
mov dl,s1
mov ah,2
int 21h
;nhap so thu 2
nhap2:
lea dx,tb2
mov ah,9
int 21h
mov ah,1
int 21h
mov s2,al
docenter2:
int 21h
cmp al,13
je endenter2
jmp docenter2
endenter2:
cmp s2,'0'
jb nhap2
cmp s2,'9'
ja nhap2
;in so thu 2
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,s2
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;hien so lon nhat
lea dx,tb4
mov ah,9
int 21h
mov ah,s1
cmp ah,s2
ja inso1
jmp inso2
inso1:
mov dl,s1
mov ah,2
int 21h
jmp endin
inso2:
mov dl,s2
mov ah,2
int 21h
jmp endin
endin:
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 4: chong trinh thuc hien nhap vao 2 so < 10, tim so lon hon
; thuat toan:
;nhap 2 ky tu tu ban phim, kiem tra co trong khoan '0' -> '9' ko
;cmp kt1,kt2, kt1<kt2 -> nhay den doan code hien kt1, else nhay den doan code hien kt2
;ko la so -> nhap lai
; ky tu ma ASCII
; 0 48
; 9 57
; a 97
; z 122
.model small
.data
s1 db 0
s2 db 0
tenct db 10,13,'nhap 2 so, tim so nho nhat$'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap so thu 1:$'
tb2 db 10,13,'Nhap so thu 2:$'
tb3 db 10,13,'Nhap sai, nhap lai:$'
tb4 db 10,13,'So nho nhat:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
;nhap so thu 1
nhap1:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov s1,al
docenter:
int 21h
cmp al,13
je endenter
jmp docenter
endenter:
cmp s1,'0'
jb nhap1
cmp s1,'9'
ja nhap1
;in so thu nhat
mov dl,10 ;in
mov ah,2 ; ra
int 21h ; mot
mov dl,13 ; dong
mov ah,2 ;trong'
int 21h
mov dl,s1
mov ah,2
int 21h
;nhap so thu 2
nhap2:
lea dx,tb2
mov ah,9
int 21h
mov ah,1
int 21h
mov s2,al
docenter2:
int 21h
cmp al,13
je endenter2
jmp docenter2
endenter2:
cmp s2,'0'
jb nhap2
cmp s2,'9'
ja nhap2
;in so thu 2
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,s2
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;hien so nho nhat
lea dx,tb4
mov ah,9
int 21h
mov ah,s1
cmp ah,s2
jb inso1
jmp inso2
inso1:
mov dl,s1
mov ah,2
int 21h
jmp endin
inso2:
mov dl,s2
mov ah,2
int 21h
jmp endin
endin:
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;bai 5: nhap vao 1 chu cai in thuong ch, in ra cac chu cai tu 'a' -> ch
;thuat toan:
;nhap vao 1 ky' tu, kiem tra ky tu do la chu cai in thuong, dung, in chu cai do
;dung vong lap loop voi so vong lap la sub ch,'a'.
.model small
.data
c db 0
tenct db 10,13,'nhap chu cai in thuong c, in ra cac chu cai tu 'a' -> c $'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap 1 chu cai in thuong:$'
tb2 db 10,13,'ket qua:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
nhap:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov c,al
docenter:
int 21h
cmp al,13
je endenter
jmp docenter
endenter:
cmp c,'a'
jb nhap
cmp c,'z'
ja nhap
;in ky tu vua nhap
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,c
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;in chuoi ky tu
lea dx,tb2
mov ah,9
int 21h
mov cl,c
and cx,00ffh
sub cx,'a'
mov dl,'a'
inc cx
inchuoi:
mov ah,2
int 21h
inc dl
loop inchuoi ;
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;bai 6: nhap vao 1 chu cai in thuong ch, in ra cac chu cai tu ch -> 'z'
;thuat toan:
;nhap vao 1 ky' tu, kiem tra ky tu do la chu cai in thuong, dung, in chu cai do
;dung vong lap loop voi so vong lap la sub 'z',ch.
.model small
.stack 100h
.data
c db 0
tenct db 10,13,'nhap chu cai in thuong c, in ra cac chu cai tu c -> 'z'$'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap 1 chu cai in thuong:$'
tb2 db 10,13,'ket qua:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
nhap:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov c,al
docenter:
int 21h
cmp al,13
je endenter
jmp docenter
endenter:
cmp c,'a'
jb nhap
cmp c,'z'
ja nhap
;in ky tu vua nhap
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,c
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;in chuoi ky tu
lea dx,tb2
mov ah,9
int 21h
mov cl,'z'
sub cl,c
and cx,00ffh
mov dl,c
inc cx
inchuoi:
mov ah,2
int 21h
inc dl
push dx
mov dl,' '
mov ah,2
int 21h
pop dx
loop inchuoi
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;bai 5 + 6: nhap vao 2 chu cai in thuong c1 va c2, in ra cac chu cai tu c1 -> c2
;thuat toan:
;nhap vao 2 ky' tu, kiem tra ky tu do la chu cai in thuong, dung, in chu cai do
;so sanh c1 voi c2, c1<c2 -> in tu c1->c2. else in tu c2->c1
;dung vong lap loop voi so vong lap la sub c1,c2 or sub c2,c1
.model small
.stack 100h
.data
c1 db 0
c2 db 0
tenct db 10,13,'nhap vao 2 chu cai in thuong c1 va c2, in ra cac chu cai tu c1 -> c2$'
pkey db 10,13,'press any key to exit ... $'
tb1 db 10,13,'Nhap ky tu 1:$'
tb2 db 10,13,'Nhap ky tu 2:$'
tb3 db 10,13,'ket qua:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
nhap1:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov c1,al
docenter1:
int 21h
cmp al,13
je endenter1
jmp docenter1
endenter1:
cmp c1,'a'
jb nhap1
cmp c1,'z'
ja nhap1
;in ky tu vua nhap
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,c1
mov ah,2
int 21h
nhap2:
lea dx,tb2
mov ah,9
int 21h
mov ah,1
int 21h
mov c2,al
docenter2:
int 21h
cmp al,13
je endenter2
jmp docenter2
endenter2:
cmp c2,'a'
jb nhap2
cmp c2,'z'
ja nhap2
;in ky tu vua nhap
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov dl,c2
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
;in chuoi ky tu
lea dx,tb3
mov ah,9
int 21h
mov ah,c1
cmp ah,c2
jb intuc1 ;in tu c1 -> c2
jmp intuc2
intuc1:
mov cl,c2
sub cl,c1
and cx,00ffh
mov dl,c1
inc cx
jmp inchuoi
intuc2:
mov cl,c1
sub cl,c2
and cx,00ffh
mov dl,c2
inc cx
jmp inchuoi
inchuoi:
mov ah,2
int 21h
inc dl
push dx
mov dl,' '
mov ah,2
int 21h
pop dx
loop inchuoi ;
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 7: nhap vao 1 so tu nhien n < 10, tinh tong cac so tu nhien tu n den 10
.model small
.stack 100h
.data
n db 0
t dw 0
tenct db 10,13,'nhap vao 1 so tu nhien n < 10, tinh tong cac so tu nhien tu n den 10$'
pkey db 10,13,'press any key to exit ... $'
xdong db 10,13,'$'
tb1 db 10,13,'Nhap so nguyen n = $'
tb2 db 10,13,'Tong= $'
cong db ' + $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
lea dx,tenct
mov ah,9
int 21h
;nhap
nhap:
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
mov n,al
cmp n,'0'
jb nhap
cmp n,'9'
ja nhap
lea dx,xdong
mov ah,9
int 21h
lea dx,tb2
mov ah,9
int 21h
mov cl,'9'
sub cl,n
inc cl
and cx,00ffh
mov dl,n
inso:
mov ah,2
int 21h
and dx,00ffh
push dx
lea dx,cong
mov ah,9
int 21h
pop dx
sub dx,'0'
mov ax,t
add ax,dx
mov t,ax
inc dx
add dx,'0'
loop inso
mov ah,2
mov dl,'1'
int 21h
mov dl,'0'
int 21h
mov ax,t
add ax,10
mov t,ax
mov dl,' '
mov ah,2
int 21h
mov dl,'='
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
mov ax,t
mov cx,0
mov bx,10
lap:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
jne lap
mov ah,2
vietso:
pop dx
add dl,'0'
int 21h
loop vietso
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 8: nhap vao 1 chu in hoa, dem bit 1 ma ASCII dang nhi phan
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
c db 0
d db 0
m db 0
tenct db 10,13,'Nhap vao 1 chu in hoa, dem bit 1 ma ASCII dang nhi phan$'
pkey db 10,13,'Press any key to exit ... $'
xdong db 10,13,'$'
tb1 db 10,13,'Nhap chu in hoa: $'
tb2 db 10,13,'Ma ASCII: $'
tb3 db 10,13,'Ma ASCII dang nhi phan: $'
tb4 db 10,13,'So bit 1:$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
nhap:
printst tb1
mov ah,1
int 21h
cmp al,'A'
jb nhap
cmp al,'Z'
ja nhap
mov m,al
printst xdong
printst tb2
mov cx,0
mov ax,0
mov al,m
pushstack:
mov dx,0
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printst xdong
printst tb3
;hien thi dang nhi phan
mov cx,0
mov al,m
and ax,00ffh
pushstack2:
xor dx,dx
mov bx,2
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp dx,1
jne tiep2
inc d
tiep2:
cmp ax,0
jne pushstack2
mov ah,2
popstack2:
pop dx
add dl,'0'
int 21h
loop popstack2
;hien so ky tu 1
printst xdong
printst tb4
mov dl,d
add dl,'0'
mov ah,2
int 21h
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ax,4ch
int 21h
main endp
;phamtuan_hp
;bai 9: dem so chu cai trong doan tu c1 den c2(c1,c2 la chu cai in hoa)
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'Dem so chu cai trong doan tu c1 den c2 (c1,c2 la chu cai in hoa)$'
xdong db 10,13,'$'
tb1 db 10,13,'Nhap 2 chu in hoa:$'
tb2 db 10,13,'c1=$'
c1 db 0
tb3 db 10,13,'c2=$'
c2 db 0
tb4 db 10,13,'So chu cai: $'
d dw 0
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst xdong
printst tb1
nhap1:
printst tb2
mov ah,1
int 21h
cmp al,'A'
jb nhap1
cmp al,'Z'
ja nhap1
mov c1,al
nhap2:
printst tb3
mov ah,1
int 21h
cmp al,'A'
jb nhap2
cmp al,'Z'
ja nhap2
mov c2,al
printst xdong
printst xdong
;in va den cac chu cai
mov ah,c1
cmp ah,c2
jb intuc1 ;in tu c1 -> c2
jmp intuc2
intuc1:
mov cl,c2
sub cl,c1
and cx,00ffh
mov dl,c1
inc cx
jmp inchuoi
intuc2:
mov cl,c1
sub cl,c2
and cx,00ffh
mov dl,c2
inc cx
jmp inchuoi
inchuoi:
mov ah,2
int 21h
inc dl
inc d
push dx
mov dl,' '
mov ah,2
int 21h
pop dx
loop inchuoi
printst xdong
printst tb4
mov cx,0
mov ax,d
pushstack:
mov dx,0
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 10: nhap vao 1 so n<8, tinh n!
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'nhap vao 1 so n<8, tinh n!$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap n=$'
n dw 0
gt dw 1
tb2 db 10,13,'n!= $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst xdong
nhap:
printst tb1
mov ah,1
int 21h
cmp al,'0'
jb nhap
cmp al,'7'
ja nhap
sub al,'0'
and ax,00ffh
mov n,ax
;tinh giai thua
tinh:
cmp n,0
jne nkhac0
jmp endtinh
nkhac0:
mov ax,gt
mov bx,n
mul bx
mov gt,ax
dec n
jmp tinh
endtinh:
printst tb2
mov ax,gt
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 11: bieu dien dang nhi phan cua n
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'bieu dien dang nhi phan cua n$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap n = $'
n dw 0
tb2 db 10,13,'dang nhi phan: $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n,ax
;hien thi dang nhi phan
printst xdong
printst tb2
xor ax,ax
mov ax,n
mov cx,0
pushstack2:
xor dx,dx
mov bx,2
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack2
mov ah,2
popstack2:
pop dx
add dl,'0'
int 21h
loop popstack2
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
;phamtuan_hp89
;bai 12; tim so nho hon
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tim so nho hon$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 2 so tu nhien:$'
tb2 db 10,13,'n1 = $'
n1 dw 0
tb3 db 10,13,'n2 = $'
n2 dw 0
tb4 db 10,13,'so nho nhat :$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
printst tb2
call scannum
mov n1,ax
printst tb3
call scannum
mov n2,ax
printst xdong
printst tb4
mov ax,n1
cmp ax,n2
jb inn1
jmp inn2
inn1:
mov ax,n1
call printnum
jmp endin
inn2:
mov ax,n2
call printnum
jmp endin
endin:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 13; tim so lon hon
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tim so lon hon$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 2 so tu nhien:$'
tb2 db 10,13,'n1 = $'
n1 dw 0
tb3 db 10,13,'n2 = $'
n2 dw 0
tb4 db 10,13,'so lon nhat : $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
printst tb2
call scannum
mov n1,ax
printst tb3
call scannum
mov n2,ax
printst xdong
printst tb4
mov ax,n1
cmp ax,n2
ja inn1
jmp inn2
inn1:
mov ax,n1
call printnum
jmp endin
inn2:
mov ax,n2
call printnum
jmp endin
endin:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 14: kiem tra hieu 2 so, tri tuyet doi < 10 thi in ra man hinh
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
n1 dw ?
n2 dw ?
h dw ?
tenct db 10,13,'kiem tra hieu 2 so, tri tuyet doi < 10 thi in ra man hinh$'
xdong db 10,13,'$'
pkey db 10,13,'Press any key to exit ... $'
tb1 db 0ah,0dh,'Nhap a = $'
tb2 db 0ah,0dh,'Nhap b = $'
tb3 db 0ah,0dh,'a - b = $'
tb4 db 0ah,0dh,'tri tuyet doi cua hieu > 9$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n1,ax
printst tb2
call scannum
mov n2,ax
printst xdong
;kiem tra hieu
mov ax,n1
cmp ax,n2
jb n2lon
jmp n1lon
n1lon:
mov ax,n1
sub ax,n2
mov h,ax
jmp endss
n2lon:
mov ax,n2
sub ax,n1
mov h,ax
jmp endss
endss:
mov ax,h
cmp ax,9
ja koinhieu
printst tb4
mov ax,h
add ax,'0'
mov dx,ax
mov ah,2
int 21h
jmp endhieu
koinhieu:
printst tb4
endhieu:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
;phamtuan_hp89
;bai 15,16,17,18: nhap n < 65536, in n ra man hinh o dang 10,2,16,8
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
printnum macro n,coso,pushstack,popstack,af,endd
mov ax,n
mov cx,0
pushstack:
xor dx,dx
mov bx,coso
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
cmp dx,9
ja AF
add dl,'0'
int 21h
jmp endd
AF:
add dl,55
int 21h
endd:
loop popstack
endm
.data
tenct db 10,13,'nhap n < 65536, in n ra man hinh$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap n = $'
n dw 0
tb2 db 10,13,'Co so 10:',9,'$'
tb3 db 10,13,'Co so 2: ',9,'$'
tb4 db 10,13,'Co so 16:',9,'$'
tb5 db 10,13,'Co so 8: ',9,'$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n,ax
printst xdong
printst tb2
mov ax,n
printnum n,10,pus10,pos10,af10,endd10
printst xdong
printst tb3
printnum n,2,pus2,pos2,af2,endd2
printst xdong
printst tb4
printnum n,16,pus16,pos16,af16,endd16
printst xdong
printst tb5
printnum n,8,pus8,pos8,af8,endd8
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
;phamtuan_hp89
;bai 19 + 20 :Co xau s1, xau s2 chua chu in hoa cua s1, s3 la s1 dao nguoc
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'Co xau s1, xau s2 chua chu in hoa cua s1, s3 la s1 dao nguoc$'
xdong db 10,13,'$'
tb1 db db 10,13,'nhap s1:$'
s1 db 70 dup(70)
l dw 0
tb2 db 10,13,'s2:$'
s2 db 70 dup(70)
tb3 db 10,13,'s3:$'
s3 db 70 dup(70)
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s1
printst tb1
lea bx,s1
dockt:
mov ah,1
int 21h
cmp al,13
je enddockt
cmp al,8
je xoa
mov [bx],al
inc bx
inc l
mov ax,l
cmp ax,69
je enddockt
jmp dockt
xoa:
dec bx
mov [bx],0
dec l
jmp dockt
enddockt:
mov [bx],'$'
printst xdong
printst s1
;xu ly s2
lea si,s1
lea di,s2
naps2:
cmp [si],'$'
je endnaps2
cmp [si],'a'
jb naptiep
cmp [si],'z'
ja naptiep
mov al,[si]
sub al,32
mov [di],al
inc si
inc di
jmp naps2
naptiep:
mov al,[si]
mov [di],al
inc si
inc di
jmp naps2
endnaps2:
mov [di],'$'
printst tb2
printst xdong
printst s2
;xu ly s3
lea si,s1
lea di,s3
mov ax,l
add di,ax
mov [di],'$'
dec di
naps3:
cmp [si],'$'
je endnaps3
mov al,[si]
mov [di],al
inc si
dec di
jmp naps3
endnaps3:
printst tb3
printst xdong
printst s3
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 21 + 22 : cho 2 xau s1,s2. kiem tra s1,s2 co bang nhau khong, co doi xung ko
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra s1,s2 co bang nhau or doi xung ko$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 2 xau$'
tb2 db 10,13,'s1:$'
s1 db 70 dup(0)
l1 dw 0
tb3 db 10,13,'s2:$'
s2 db 70 dup(0)
l2 dw 0
cobang db 10,13,'s1,s2 bang nhau$'
kobang db 10,13,'s1,s2 khong bang nhau$'
codoi db 10,13,'s1,s2 doi xung nhau$'
kodoi db 10,13,'s1,s2 khong doi xung nhau$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
;nap s1
printst tb2
lea si,s1
naps1:
mov ah,1
int 21h
cmp al,13
je endnaps1
mov [si],al
inc l1
inc si
mov ax,l1
cmp ax,69
je endnaps1
jmp naps1
endnaps1:
mov [si],'$'
printst xdong
printst s1
;nap s2
printst tb3
lea si,s2
naps2:
mov ah,1
int 21h
cmp al,13
je endnaps2
mov [si],al
inc l2
inc si
mov ax,l2
cmp ax,69
je endnaps2
jmp naps2
endnaps2:
mov [si],'$'
printst xdong
printst s2
printst xdong
;kiem tra bang nhau
mov ax,l1
cmp ax,l2
jne kbang
cmp ax,l2
jne kdoi
lea si,s1
lea di,s2
ktbang:
mov al,[si]
cmp al,'$'
je bang
cmp al,[di]
jne kbang
inc si
inc di
jmp ktbang
bang:
printst cobang
jmp endktbang
kbang:
printst kobang
jmp endktbang
endktbang:
;kiem tra doi xung
lea si,s1
lea di,s2
add di,l2
dec di
ktdoi:
mov al,[si]
cmp al,'$'
je doi
cmp al,[di]
jne kdoi
inc si
dec di
jmp ktdoi
doi:
printst codoi
jmp endktdoi
kdoi:
printst kodoi
jmp endktdoi
endktdoi:
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 23 + 24 + 25 : nhap xau s,in do dai, den chu so trong s, lay xau con tu vi tri i, n ky tu
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'nhap xau s,in do dai, den chu so trong s, lay xau con tu vi tri i, n ky tu$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap s:$'
s db 70 dup(0)
l dw 0
tb2 db 10,13,'do dai:$'
tb3 db 10,13,'so ky tu so trong s:$'
d dw 0
tb4 db 10,13,'Nhap vi tri bat dau i= $'
i dw 0
tb5 db 10,13,'Nhap do dai xau con n= $'
n dw 0
sc db 50 dup(0)
tb6 db 10,13,'Xau con : $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea bx,s ;
dockt:
mov ah,1
int 21h
cmp al,13
je enddockt
mov [bx],al
inc bx
inc l
mov ax,l
cmp ax,69
je enddockt
jmp dockt
enddockt:
mov [bx],'$'
printst xdong
printst xdong
printst tb2
mov ax,l
call printnum
printst xdong
;den ky tu so trong s
lea si,s
dec si
dem:
inc si
mov al,[si]
cmp al,'$'
je enddem
cmp al,'0'
jb dem
cmp al,'9'
ja dem
inc d
jmp dem
enddem:
;in so ky tu so
printst tb3
mov ax,d
call printnum
printst xdong
;nhap i,n
nhapi:
printst tb4
call scannum
cmp ax,l
ja nhapi
mov i,ax
nhapn:
printst tb5
call scannum
mov bx,l
sub bx,i
cmp ax,bx
ja nhapn
mov n,ax
;lay xau con
lea si,s
lea di,sc
add si,i
mov cx,n
rep movsb
mov [di],'$'
printst xdong
printst tb6
printst sc
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
;phamtuan_hp89
;bai 26: nhap 1 ky tu ch, in ra man hinh 10 dong, moi dong 10 ky tu ch
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'nhap 1 ky tu ch, in ra man hinh 10 dong, moi dong 10 ky tu ch$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 1 ky tu:$'
kt db 0
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap 1 ky tu
printst tb1
mov ah,1
int 21h
mov kt,al
printst xdong
;in 10x10 ky tu ch
mov cx,10
indong:
push cx
mov cx,10
inch:
mov dl,kt
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
loop inch
printst xdong
pop cx
loop indong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 27: tao s1 tu s loai bo cac dau cach
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tao s1 tu s loai bo cac dau cach$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap xau s:$'
s db 70 dup(0)
tb2 db 10,13,'s1:$'
s1 db 70 dup(0)
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea si,s
mov dx,si
add dx,70
nhaps:
mov ah,1
int 21h
cmp al,13
je endnhaps
mov [si],al
inc si
cmp si,dx
je endnhaps
jmp nhaps
endnhaps:
mov [si],'$'
printst xdong
;xu ly sc
lea si,s
lea di,s1
gans1:
cmp [si],'$'
je endgans1
cmp [si],' '
je gantiep
mov al,[si]
mov [di],al
inc di
gantiep:
inc si
jmp gans1
endgans1:
inc di
mov [di],'$'
printst xdong
printst tb2
printst s1
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 28: kiem tra 1 ky tu ch trong xau s hay ko
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra 1 ky tu ch trong xau s hay ko$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap xau s : $'
s db 70 dup(0)
tb2 db 10,13,'nhap 1 ky tu ch : $'
ch db 70 dup(0)
cch db 10,13,'Co ch trong s $'
kch db 10,13,'Khong co ch trong s $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea si,s
mov ah,1
nhap:
int 21h
cmp al,13
je endnhap
mov [si],al
inc si
jmp nhap
endnhap:
mov [si],'$'
printst xdong
printst xdong
printst tb2
mov ah,1
int 21h
mov ch,al
printst xdong
;kiem tra ch trong s
lea si,s
kiemtra:
cmp [si],'$'
je koch
cmp [si],ch
je coch
inc si
jmp kiemtra
koch:
printst kch
jmp endkiemtra
coch:
printst cch
endkiemtra:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 29:dem so luong ky tu 'A' trong xau s
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra 1 ky tu ch trong xau s hay ko$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap xau s : $'
s db 70 dup(0)
tb2 db 10,13,'So luong ky tu A trong s : $'
d dw 0
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea si,s
mov ah,1
nhap:
int 21h
cmp al,13
je endnhap
cmp al,65
jne tiep
inc d
tiep:
mov [si],al
inc si
jmp nhap
endnhap:
mov [si],'$'
printst xdong
printst xdong
printst tb2
mov ax,d
call printnum
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 30: tinh tong cac ky tu so trong sau s
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra 1 ky tu ch trong xau s hay ko$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap xau s : $'
s db 70 dup(0)
tb2 db 10,13,'So luong ky tu so trong s : $'
d dw 0
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea si,s
mov ah,1
nhap:
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb tiep
cmp al,'9'
ja tiep
inc d
tiep:
mov [si],al
inc si
jmp nhap
endnhap:
mov [si],'$'
printst xdong
printst xdong
printst tb2
mov ax,d
call printnum
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 31: nhap 1 so n, tinh tong n den 10
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
n db 0
t dw 0
tenct db 10,13,'nhap vao 1 so tu nhien n < 10, tinh tong cac so tu nhien tu n den 10$'
pkey db 10,13,'press any key to exit ... $'
xdong db 10,13,'$'
tb1 db 10,13,'Nhap so nguyen n = $'
tb2 db 10,13,'Tong= $'
cong db ' + $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
;hien ten chuong trinh
printst tenct
;nhap
nhap:
printst tb1
mov ah,1
int 21h
cmp al,'0'
jb nhap
cmp al,'9'
ja nhap
mov n,al
printst xdong
printst tb2
mov cx,0
mov cl,'9'
sub cl,n
inc cl
mov dl,n
inso:
mov ah,2
int 21h
and dx,00ffh
push dx
printst cong
pop dx
sub dx,'0'
mov ax,t
add ax,dx
mov t,ax
inc dx
add dx,'0'
loop inso
mov ah,2
mov dl,'1'
int 21h
mov dl,'0'
int 21h
mov ax,t
add ax,10
mov t,ax
mov dl,' '
mov ah,2
int 21h
mov dl,'='
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
mov ax,t
mov cx,0
mov bx,10
lap:
mov dx,0
div bx
push dx
inc cx
cmp ax,0
jne lap
mov ah,2
vietso:
pop dx
add dl,'0'
int 21h
loop vietso
;press any key
printst pkey
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 32:nhap n so tu nhien trong doan [0..9], tinh tong cac so nay
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'nhap n so tu nhien trong doan [0..9], tinh tong cac so nay$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap cac so can tinh tong, ket thuc bang enter:$'
so dw 20 dup(0)
t dw 0
cong db ' + $'
bang db ' = $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
lea si,so
mov cx,0
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
mov [si],al
sub al,'0'
and ax,00ffh
add t,ax
inc cx
cmp cx,20
je endnhap
inc si
jmp nhap
endnhap:
printst xdong
printst xdong
lea si,so
intong:
mov ah,2
mov dl,[si]
int 21h
inc si
cmp cx,1
je koincong
printst cong
koincong:
loop intong
printst bang
mov ax,t
call printnum
printst xdong
;press any key
printst pkey
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 33: tinh tong cac so chan trong doan [0..100]
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tinh tong cac so chan trong doan [0..100]$'
xdong db 10,13,'$'
tb1 db 10,13,'Tong = $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst xdong
printst tb1
mov ax,0
mov bx,0
tinh:
add bx,2
add ax,bx
cmp bx,100
je endtinh
jmp tinh
endtinh:
call printnum
printst xdong
printst xdong
;press any key
printst pkey
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 34:tinh tong cac so le trong doan [0,100]
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tinh tong cac so le trong doan [0..100]$'
xdong db 10,13,'$'
tb1 db 10,13,'Tong = $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst xdong
printst tb1
mov ax,0
mov bx,1
tinh:
add bx,2
add ax,bx
cmp bx,99
je endtinh
jmp tinh
endtinh:
add ax,1
call printnum
printst xdong
printst xdong
;press any key
printst pkey
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
;phamtuan_hp89
;bai 35:kiem tra n la so chan hay so le
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra n la so chan hay so le$'
xdong db 10,13,'$'
tb1 db 10,13,'Nhap n = $'
n dw 0
sochan db ' la so chan$'
sole db ' la so le$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n,ax
printst xdong
mov ax,n
call printnum
mov ax,n
mov bx,2
xor dx,dx
div bx
cmp dx,0
je nchan
printst sole
jmp thoat
nchan:
printst sochan
thoat:
printst xdong
;press any key
printst pkey
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
printnum endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
scannum endp
Bạn đang đọc truyện trên: AzTruyen.Top