35baiASM-1..12
;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
;in tong
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:
;in gt
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
ret
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
ret
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
ret
printnum endp
Bạn đang đọc truyện trên: AzTruyen.Top