assem21-30
;Bai 21/Nhap 2 xau tuy y cho biet 2 xau do bang nhau khong(ve do dai va noi dung).
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
n dw ?
xau1 db 80 dup (?)
xau2 db 80 dup (?)
over:
@write'Nhap xau thu nhat: '
xor bx,bx
mov ah,1
nhap1:int 21h
cmp al,0dh
je het1
mov xau1[bx],al
inc bx
jmp nhap1
het1:mov n,bx
@xuongdong
@write'Nhap xau thu hai: '
xor bp,bp
mov ah,1
nhap2:int 21h
cmp al,0dh
je het2
mov xau2[bp],al
inc bp
jmp nhap2
het2:@xuongdong
sosanh:cmp bx,bp
jne thoat
mov bx,n
xor bx,bx
xor bp,bp
sosanh2:mov dl,xau1[bx]
cmp dl,xau2[bp]
jne thoat
inc bx
inc bp
cmp bx,n
jb sosanh2
@write'Hai xau da cho co noi dung nhu nhau'
jmp het
thoat:@write'hai xau da cho khac nhau'
het:int 20h
include proc.asm code ends end start
;Bai 22/Nhap mot xau chua ho ten mot nguoi, tach va in ra xau chua ten.(su dung thu vien).
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
xau db 80 dup (?)
ten db 30 dup (?)
over: @write'Ho va ten: '
xor bx,bx
mov ah,1
nhap: int 21h
cmp al,0dh
je hetnhap
mov xau[bx],al
inc bx
jmp nhap
hetnhap:
@xuongdong @write'Ten la: '
mov dl,32
dec bx
xor bp,bp
kt:
cmp xau[bx],dl
jne qua
dec bx
jmp kt
qua:xor cx,cx
tru:cmp xau[bx],dl
je qua1
dec bx
inc cx
jmp tru
qua1:inc bx
mov dl,xau[bx]
mov ten[bp],dl
inc bp
loop qua1
mov ten[bp],'$'
mov ah,9
lea dx,ten
int 21h
het:int 20h
include proc.asm code ends end start
;Bai 23/Nhap 1 = N = 8. Hay tinh N!. (duoc dung thu vien).
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
n dw ?
over:
@write'Nhap n= '
call nhap_so
mov n,ax
@xuongdong
call in_so
@write'!= '
cmp n,0
je qua
mov cx,n
mov ax,1
lap:
mul cx
loop lap
mov cx,10
div cx
call in_so
mov ax,dx
call in_so
jmp het
qua:
mov ah,2
mov dl,'1'
int 21h
het:
int 20h
include proc.asm
code ends
end start
;Bai 24/Nhap 1<=N<=8.Hay tinh N!(khong dung thu vien)
code segment
assume cs:code
org 100h
start:jmp over
tb1 db 'Nhap N=$'
tb2 db 13,10
N db ?,'?=$'
over:
mov dx,offset tb1
mov ah,9
int 21h
mov N,al
cmp al,'0'
je inra
xor cx,cx
mov cl,N
and cl,0fh
inra:
mov ax,1
nhan:mul cx
loop nhan
push ax
mov ah,9
lea dx,tb2
int 21h
pop ax
mov bx,10
xor cx,cx
chiatiep:xor dx,dx
div bx
push dx
inc cx
cmp ax,0
jmp chiatiep
mov ah,2
layra:pop dx
or dl,30h
int 21h
loop layra
int 20h
code ends
end start
;Bai 25/Cho BX=mot so hexa in ra so do.
code segment
assume cs:code
org 100h
start: jmp over
xau db 'So da cho la: $'
over:
mov bx,0D3F4h
mov ah,9
lea dx,xau
int 21h
mov cl,12
mov ah,2
lap:
mov dx,bx
shr dx,cl
and dl,0fh
cmp dl,9
jbe so
add dl,7
so:
add dl,30h
int 21h
sub cl,4
cmp cl,0
jge lap
int 20h
code ends
end start
;Bai 26/Nhap 1 = N = 360. Hay tinh tong S = 1 + 2 + … + N. (duoc dung thu vien).
include mylib.mac
code segment
assume cs:code
org 100h
start:jmp over
N dw ?
over:
@write 'Nhap N='
call Nhap_so
mov N,ax
xor ax,ax
mov cx,N
cong:add ax,cx
loop cong
@xuongdong
@write 'tong tu 1-->'
push ax
mov ax,N
call in_so
@write 'la:'
pop ax
mov bx,10
xor dx,dx
div bx
cmp ax,0
je qua
call in_so
qua:mov ax,dx
call in_so
int 20h
include proc.asm
code ends
end start
;Bai 27/ Nhap mot mang Word. Hay tim Max, Min va in ra.(su dung thu vien).
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over a dw 30 dup (?)
max dw ?
min dw ?
n dw ?
over:
@write'Nhap so phan tu n= '
call nhap_so
mov n,ax
@write'Nhap mang: '
mov cx,n
xor bx,bx
nhap:@xuongdong
@write'Nhap mot phan tu: '
call nhap_so
mov a[bx],ax
add bx,2
loop nhap
xor bp,bp
mov cx,n
push a[bp] a[bp]
pop min max
timmax:mov ax,a[bp]
cmp ax,max
jbe timmin
mov max,ax
jmp het
timmin:cmp min,ax
jb het
mov min,ax
het:add bp,2
loop timmax
@xuongdong
@write'Max= '
mov ax,max
call in_so
@xuongdong
@write'Min= '
mov ax,min
call in_so
int 20h
include proc.asm
code ends end start
;Bai 28/Nhap vao mot so nhi phan toi da 16 bite in ra cac bit co nghia.
code segment
assume cs:code
org 100h
start: jmp over
xau1 db 'nhap mot so nhi phan: $'
xau2 db 0ah,0dh,'Cac bit co nghia: $'
over:
mov ah,9
lea dx,xau1
int 21h
mov ah,1
xor bx,bx
nhap:int 21h
cmp al,0dh
je thoat
sub al,30h
shl bx,1
or bl,al
jmp nhap
thoat:mov ah,9
lea dx,xau2
int 21h
cmp bx,0
je inso0
mov cx,16
xoa:rol bx,1
jc qua
dec cx
jmp xoa
qua:mov ah,2
jmp inso1
inso:rol bx,1
jc inso1
mov dl,'0'
jmp inra
inso1:mov dl,'1'
inra:int 21h
dec cx
cmp cx,0
ja inso
jmp het
inso0:mov ah,2
mov dl,'0'
int 21h
het:int 20h
code ends
end start
;Bai 29/Nhap hai ki tu in theo thu tu tu dien.
code segment
assume cs:code
org 100h
start: jmp over
xau1 db 'Nhap ky tu thu nhat: $'
xau2 db 0ah,0dh,'Nhap ky tu thu 2: $'
xau3 db 0ah,0dh,'In theo thu tu tu dien: $'
over:
mov ah,9
lea dx,xau1
int 21h
mov ah,1
int 21h
mov bl,al
mov ah,9
lea dx,xau2
int 21h
mov ah,1
int 21h
mov bh,al
mov ah,9
lea dx,xau3
int 21h
mov cl,bl
cmp bh,cl
ja inbl
xchg bh,bl
inbl:mov ah,2
mov dl,bl
int 21h
mov ah,2
mov dl,' '
int 21h
mov ah,2
mov dl,bh
int 21h
het:int 20h
code ends
end start
;Bai 30/Cho 1 = a,b = 9. tinh trung binh cong cua chung.
code segment
assume cs:code
org 100h
start: jmp over
xau1 db 'Nhap a= $'
xau2 db 0ah,0dh,'Nhap b= $'
xau3 db 0ah,0dh,'TBC= $'
xau4 db '.5$'
over:
mov ah,9
lea dx,xau1
int 21h
mov ah,1
int 21h
mov bl,al
mov ah,9
lea dx,xau2
int 21h
mov ah,1
int 21h
xor ah,ah
add bx,ax
mov ah,9
lea dx,xau3
int 21h
mov cx,bx
shr bx,1
mov ah,2
mov dx,bx
int 21h
test cx,1
je qua
mov ah,9
lea dx,xau4
int 21h
qua:
int 20h
code ends
end start
Bạn đang đọc truyện trên: Truyen247.Pro