BAi thay Thanh
1. Nhap vao 1 chuoi ky tu, in ra dao nguoc va bo khoang trang
Code:
.model small
.stack 100h
.data
msg1 db 'nhap vao mot chuoi: $'
msg2 db 13, 10, 'chuoi dao nguoc da duoc loai bo khoang trang la $'
.code
mov ax,@data
mov ds,ax
mov ah,9
lea dx,msg1
int 21h
mov cx,0
nhap:
mov ah,1
int 21h
cmp al, 32 ;co phai khoang trang
je nhap
cmp al,13 ; neu Enter thi ket thuc nhap
je thongbaoxuat
push ax
inc cx
jmp nhap
thongbaoxuat:
mov ah,9
lea dx,msg2
int 21h
xuat:
pop ax
mov dl,al
mov ah,2
int 21h
loop xuat
mov ah,4ch
int 21h
end
__________________________________________________________
2.Nhap vao mot chuoi, loai bo ky tu trang thua
.model small
.stack 100h
.data
msg1 db 'nhap vao mt chuoi: $'
msg2 db 13, 10, 'chuoi da duoc loai bo khoang trang la $'
chuoicuoi DB 80 dup('!')
.code
mov ax,@data
mov ds,ax
lea dx,msg1
lea si, chuoicuoi
cld ; dat co dinh huong tang
; thong bao thu 1
mov ah,9
int 21h
mov cx,0
nhap:
mov ah,1
int 21h
cmp al, 32 ;co phai khoang trang
je nhap
cmp al,13
je thongbaoxuat
;push ax
mov chuoicuoi[si], al
;inc cx
inc si
jmp nhap
thongbaoxuat:
inc cx
mov chuoicuoi[si], '$'
mov ah,9
lea dx,msg2
int 21h
xuat:
;pop ax
;mov dl,al
;mov ah,2
;int 21h
;loop xuat
mov ah, 9
lea dx, chuoicuoi
int 21h
mov ah,4ch
int 21h
end
---------------------------------------------------------------
3. Copy 1 chuoi............
.model small
.stack 100h
.data
s1 db 'abcd'
s2 db 4 dup (?)
.code
mov ax,@data
mov ds,ax
lea si,s1
lea di,s2+3
mov cx,4
cld
lap:
movsb
sub di,2
loop lap
mov ah,9
lea dx,s2
mov ah,4ch
int 21h
end
--------------------------------------------------------------
4.Dem so ky tu.....
demkytu proc
mov ax,0
repeat:
inc cx
mov bx,10
duv bx
cmp ax,0
jne repeat
output:
mov ah,2
add cx,30h
mov dl,cl
int 21h
demkytu endp
-------------------------------------------------------------
5.In dao nguoc cua so co nhieu chu so..........
.model small
.strack 100h
.data
.code
main proc
mov ax,100
mov ah,4ch
int 21h
main endp
output proc
mov cx,0
repeat:
inc cx
mov bx,10
div bx
push dx
cmp ax,0
jne repeat
in:
pop dx
mov ah,2
int 21h
loop in
ret
output endp
end main
--------------------------------------------------------------
6.Nhap vao 1 chuoi va cho biet tong ky tu da nhap.........
.data
s db 80 dup ('$')
.code
mov ax,@data
mov ds,ax
lea dx,s
mov ah,0Ah
int 21h
lea di,s+1
mov bl,[di]
cld,0
lea si,s+2
lap:
losb
mov dl,al
mov ah,2
int 21h
loop lap
------------------------------------------------------------------
7.Nhap vao 1 chuoi, nhap vao 1 ky tu va dem xem ky tu vua xuat hien trong chuoi bao nhieu
.data
s db 80 dup ('$')
.code
main proc
mov ax,@data
mov ds,ax
lea dx,3
mov ah,0Ah
int 21h
lea si,s
mov cx,[si]
mov ah,1
cld,0
add si,1
mov dl,0
lap:
losb
cmp bl,al
je dem
jmp boqua
dem:
inc dl
boqua:
loop lap
end main
-----------------------------------------------------
8.Nhap vao 1 day ky tu, khi nhan enter thi dung va xuat ra chuoi nguoc lai
.code
mov cx,0
lap_nhap:
mov ah,1
int 21h
cmp al,0dh
je xuat
push ax
inc cx
jmp lap_nhap
mov ah,2
xuat:
pop dx
int 21h
loop xuat
mov ah,4ch
int 21h
------------------------------------------------------
9.Nhap vao 1 day ky tu, ket thuc khi nhan enter va chuyen ra thap phan
.code
mov bx,0
input:
mov ah,1
int 21h
cmp dl,0dh
je stop_input
sub al,30h
mov ah,0
push ax
mov ax,10
mul bx
mov bx,ax
pop ax
add bx,ax
jmp input
stop_input:
ret
-----------------------------------------------------------
10.Nhap vao 1 ky tu, kiem tra lan luot co pai la ky tu so ko, pai thi in ra day so do
.model small
.stack 100h
.data
tb1 db 13, 10,'moi ban nhap vao ki tu $'
xuong_dong db 13, 10, '$'
.code
main proc
mov ax,@data
mov ds,ax
mov cx,0
call nhap
mov ah,4ch
int 21h
main endp
nhap proc
;mov bx,0
lea dx,tb1
mov ah,9
int 21h
mov ah,1
int 21h
cmp al,0dh
je bosung
cmp al,30h
jb nhap
cmp al,39h
jbe luu
; > '9'
cmp al,41h ;'A'
jb nhap
cmp al,5ah ;'Z'
jbe luu
; > 'Z'
cmp al,61h ;'a'
jb nhap
cmp al,7ah ;'z'
jbe luu
jmp nhap
luu:
mov ah,0
inc cx
push ax
jmp nhap
bosung:
;kiemtra
cmp cx,0
jne dem0
jmp kt
dem0:
;xuong dong truoc khi xuat ra
mov ah, 9
lea dx, xuong_dong
int 21h
dem:
pop ax
cmp al, 30h ;'0'
jb ko_in
cmp al,39h ;'9'
ja ko_in
;inc bx
mov ah, 2
mov dl, al
int 21h
ko_in:
loop dem
kt:
;mov ah,2
;int 21h
ret
nhap endp
end main
------------------------------------------------------
11.Tinh tong cua day 1+2+3...+n
.model small
.stack 100h
.data
tb1 db 'Nhap so n = $'
tb3 db 'Tong 1+2+...+n=$'
.code
main proc
mov bx,0
mov ax,@data
mov ds,ax
mov dx,offset tb1
mov ah,09
int 21h
xor bx,bx
nhap:
mov ah,1
int 21h
cmp al,0dh
je xuat
sub al,30h
mov ah,0
push ax
mov ax,0010d
mul bx
mov bx,ax
pop ax
add bx,ax
jmp nhap
xuat:
mov ah,2
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dx,offset tb3
mov ah,09
int 21h
mov cx,bx
xor ax,ax
tinh:
add ax,cx
loop tinh
lap1:
xor dx,dx
mov bx,0010d
div bx
push dx
inc cx
cmp ax,0
je print1
jmp lap1
print1:
pop dx
mov ah,2
add dl,30h
int 21h
loop print1
main endp
mov ah,4ch
int 21h
end main
end.
---------------------------------------------------
12.Tong hai so co a+b
.model tiny
.stack 100h
.data
str1 db 'Nhap so thu nhat $'
str2 db 13,10,'Nhap so thu hai $'
str3 db 13,10,'Tong la $'
n dw 0
m dw 0
.code
mov ax,@data
mov ds,ax
mov ah,9
lea dx,str1
int 21h
nhap1:
mov ah,1
int 21h
;kiem tra xem so vua nhap vao co = 13(enter) ko?->neu la enter thi nhay den ra1 de nhap so thu 2
cmp al,13
je ra1
mov ah,0
sub al,'0'
mov cx,n;lap lai lan thu n
xchg ax,cx;hoan vi cx vao ax va nguoc lai
mov bx,10
mul bx
add ax,cx
mov n,ax
jmp nhap1
ra1:
mov ah,9
lea dx,str2
int 21h
nhap2:
mov ah,1
int 21h
cmp al,13
je ra2
mov ah,0
sub al,'0'
mov cx,m
xchg ax,cx
mov bx,10
mul bx
add ax,cx
mov m,ax
jmp nhap2
ra2:
mov ah,9
lea dx,str3
int 21h
mov bx,m
add bx,n
mov ax,bx
mov dx,0
mov cx,0
mov bx,10
chia:
div bx
push dx
inc cx
cmp ax,0
je inso
mov dx,0
jmp chia
inso:
pop dx
add dx,'0'
mov ah,2
int 21h
loop inso
mov ah,4ch
int 21h
end
----------------------------------------------------------------
Bạn đang đọc truyện trên: AzTruyen.Top