assem31-43
;Bai 31/nhap mot xau. xau do co doi xung khong.(CN30.ASM)
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
xau db 80 dup (?)
over:
@write'Nhap mot xau tuy y: '
xor bx,bx
mov ah,1
nhap:
int 21h
cmp al,0dh
je hetnhap
mov xau[bx],al
inc bx
jmp nhap
hetnhap:
@xuongdong
xor bp,bp
sosanh:
dec bx
mov dl,xau[bx]
cmp dl,xau[bp]
jne thoat
inc bp
cmp bx,bp
jae sosanh
@write'Xau da cho la doi xung'
jmp het
thoat:
@write'Xau da cho khong doi xung'
het:
int 20h
include proc.asm
code ends
end start
;Bai 32/Cho AX = 1 so nguyen 2 byte co dau. hay in so nguyen do ra man hinh.(CN33.ASM)
code segment
assume cs:code
org 100h
start: jmp over
xau db 'So da cho la: $'
over:
mov ah,9
lea dx,xau
int 21h
mov ax,-54321
push ax
mov ah,2
mov dl,'-'
int 21h
pop ax
neg ax
xor cx,cx
mov bx,10
chia:
xor dx,dx
div bx
inc cx
push dx
cmp ax,0
jg chia
mov ah,2
inra:
pop dx
add dx,30h
int 21h
loop inra
int 20h
code ends
end start
;Bai 33/Nhap mot xau.dem so tu cua xau
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
xau db 80 dup (?)
over:
@write'Nhap xau: '
xor bx,bx
mov ah,1
nhap:
int 21h
cmp al,0dh
je hetnhap
mov xau[bx],al
inc bx
jmp nhap
hetnhap:
mov dl,32
xor bp,bp
kt:
cmp xau[bp],dl
jne lap1
inc bp
jmp kt
lap1:xor cx,cx
dec bx
lap:
cmp xau[bx],dl
jne qua
dec bx
jmp lap
qua:cmp xau[bx],dl
je qua1
dec bx
jmp qua
qua1:inc cl
cmp bx,bp
jge lap
het: @xuongdong
@write'So tu cua xau la: '
xor ah,ah
mov al,cl
call inso
int 20h
include proc.asm
code ends
end start
;Bai 34/Cho 1 = a,b = 360. Tinh tich A*B bang thuat toan nhan an do.
include mylib.mac
code segment
assume cs:code
org 100h
start: jmp over
a dw ?, 0ah,0dh,'$'
b dw ?
over:
@write'Nhap a= '
call nhap_so
mov a,ax
@xuongdong
@write'Nhap b= '
call nhap_so
@xuongdong
mov b,ax
mov bx,b
mov dx,bx
mov ax,a
xor cx,cx
lap:
test dl,1
je qua
add cx,ax
qua:
shl ax,1
shr bx,1
mov dx,bx
cmp bx,0
jne lap
mov ax,cx
@write'Tich = '
cmp ax,10
jb qua2
mov cx,10
div cx
call in_so
mov ah,2
add dx,30h
int 21h
jmp het
qua2:call in_so
het:
int 20h
include proc.asm
code ends
end start
;Bai 35/Su dung chuc nang AH=8 de nhap mot day ki tu neu la ki tu va dau cach thi in ra.
code segment
assume cs:code
org 100h
start: jmp over
xau db 'Nhap day ky tu chi in chu cai va dau cach: $'
xau2 db 0ah,0dh,'$'
over:
mov ah,9
lea dx,xau
int 21h
lea dx,xau2
int 21h
nhaptiep:
mov ah,8
int 21h
cmp al,32
je inra
cmp al,'A'
jb qua
cmp al,'Z'
jbe inra
cmp al,'a'
jb qua
cmp al,'z'
ja qua
inra:
mov ah,2
mov dl,al
int 21h
jmp nhaptiep
qua:
cmp al,27
jne nhaptiep
int 20h
code ends
end start
;Bai 36/Nhap mot mang mot chieu cac word.Tinh tong cac phan tu chan cua mangva in ra tong(Thu vien)
Include mylib.mac
Code segment
Assume cs:code
Org 100h
Start:jmp over
N dw 0
A dw 80 dup(?)
Over:
@write’nhap so phan tu cua mang:’
Call nhap_so
Mov n,ax
@xuongdong
@write’nhap mang vao:’
Lea di,a
Mov cx,n
Cld
Lap:
@xuongdong
Call nhap_so
Stosw
Loop lap
Xor si,si
Xor ax,ax
Mov cx,n
Lap1:
test a[si],1
Jnz sole
Add ax,a[si]
Sole:
add si,2
Loop lap1
@xuongdong
@write’tong cac phan tu chan la:’
Call in_so
Int 20h
Include proc.asm
Code ends
End start
;Bai 37/Nhap mot mang mot chieu cac word.Tinh tong cac phan tu le cua mang va in ra tong(thu vien)
Include mylib.mac
Code segment
Assume cs:code
Org 100h
Start:jmp over
N dw 0
A dw 80 dup(?)
Over:
@write’nhap so phan tu cua mang:’
Call nhap_so
Mov n,ax
@xuongdong
@write’nhap mang vao:’
Lea di,a
Mov cx,n
Cld
Lap:
@xuongdong
Call nhap_so
Stosw
Loop lap
Xor si,si
Xor ax,ax
Mov cx,n
Lap1:
Test a[si],1
Jz sochan
Add ax,a[si]
Sochan:
add si,2
loop lap1
@xuongdong
@write’tong cac phan tu le la:’
Call in_so
Int 20h
Include proc.asm
Code ends
End start
;Bai 38/Viet thu tuc in mang de in mang mot chieu cac word(cac byte).Hay nhap mot mang goi thu tuc va in ra mang. dao nguoc cac phan tu trong mang. goi thu tuc do de in ra mang dao.
include mylib.mac
code segment
assume cs:code
org 100h
start:jmp over
a dw 20 dup(?)
n dw ?
over:
@write'cho so phan tu n='
call nhap_so
mov n,ax
lea bx,a
mov cx,n
nhap:@xd
@write'nhap mot phan tu:'
call nhap_so
mov [bx],ax
push ax
add bx,2
loop nhap
@xuongdong
@write'mang da nhap la:'
call in_mang
xor bx,bx
mov cx,n
dao:pop a[bx]
add bx,2
loop dao
@xuongdong
@write'mang da dao la:'
call in_mang
int 20h
include proc.asm
in_mang proc
push ax bx cx
lea bx,a
mov cx,n
inra:mov ax,[bx]
call in_so
@write ' '
add bx,2
loop inra
pop cx bx ax
ret in_mang endp
code ends end start
;Bai 39/Nhap mot xau ki tu chuyen cac ki tu la chu thuong cua xau do ra xau khac va in ra xau thu hai(su dung thu vien)
include mylib.mac
code segment
assume cs:code
org 100h
start:jmp over
xau1 db 80 dup('$')
xau2 db 80 dup('$')
over:
@write'nhap xau:'
lea di,xau1
xor cx,cx
cld
mov ah,1
lap:int 21h
cmp al,13
je chuyen
stosb
inc cx
jmp lap
chuyen:xor si,si
lea di,xau2
duyet:mov al,xau1[si]
cmp al,'a'
jb qua
cmp al,'z'
ja qua
stosb
qua:inc si
loop duyet
@xuongdong
@write'xau thu hai la:'
mov ah,9
lea dx,xau2
int 21h
int 20h
include proc.asm
code ends
end start
;Bai 40/Nhap mot xau ki tu chuyen cac ki tu la chu hoa cua xau do ra xau khac va in ra xau thu 2(su dung thu vien)
include mylib.mac
code segment
assume cs:code
org 100h
start:jmp over
xau1 db 80 dup('$')
xau2 db 80 dup('$')
over:
@write'nhap xau:'
lea di,xau1
xor cx,cx
cld
mov ah,1
lap:int 21h
cmp al,13
je chuyen
stosb
inc cx
jmp lap
chuyen:xor si,si
lea di,xau2
duyet:mov al,xau1[si]
cmp al,'A'
jb qua
cmp al,'Z'
ja qua
stosb
qua:
inc si
loop duyet
@xuongdong
@write'xau thu hai la:'
mov ah,9
lea dx,xau2
int 21h
int 20h
include proc.asm
code ends
end start
;Bai 41/Nhap mot mang Byte hoac Word, sap xep mang va in ra mang da sap xep. (Su dung PROC.ASM va MYLIB.MAC).
include MYLIB.MAC
Code Segment
org 100h
assume cs:code
start: JMP over
A DW 20 DUP (0)
N DW ?
I DW ?
J DW ?
Over:
@write 'Nhap so phan tu='
Call Nhap_so
Mov n,ax
xor bx,bx
xor cx,cx
@Xuong_dong
LapNhap:@Write 'Nhap so thu '
Mov ax,cx
Call IN_SO
@Write ':'
Call Nhap_so
mov a[bx],ax
@Xuong_dong
Add bx,2
inc cx
cmp cx,n
JB lapnhap
;Sap xep mang
MOV I,0
@FOR_I: ;For i:=0 To N-1 DO
PUSH I
POP J
MOV BX,I
ADD BX,I
@FOR_J: ;For J:=1 To N DO
INC J
MOV BP,J
CMP BP,N
JAE @ENDFOR_J
ADD BP,J
MOV AX,A[BP]
CMP A[BX],AX
JBE Qua
MOV BX,BP
Qua:
JMP @FOR_J
@ENDFOR_J:
MOV BP,I
ADD BP,BP
PUSH A[BP] A[BX]
POP A[BP] A[BX]
INC I
MOV AX,I
CMP AX,N
JB @FOR_I
@ENDFOR_I:
@Writeln '----->>> In mang <<<-----'
XOR BX,BX
MOV CX,N
@LapIN:
MOV AX,A[BX]
Call IN_SO
@Write ' '
ADD BX,2
LOOP @LapIN
INT 20h
Include PROC.ASM ;Khai bao thu vien thu tuc
code ends
End start
;Bai 42/Nhap mot xau chu thuong, in ra xau chu hoa. (Su dung MYLIB.MAC).
Include MYLIB.MAC ;Khai bao thu vien MACRO
Code Segment
org 100h
assume cs:code
start: JMP over
xau DB 80 Dup ('$')
Over:
@Write 'Nhap mot xau:'
MOV AH,1
LEA DI,Xau
XOR CX,CX
LapNhap:
INT 21h
CMP AL,13
JE EndLapNhap
Cmp AL,'a'
JB Qua
CMP AL,'z'
JA Qua
XOR AL,20h
Qua:
MOV [DI],AL
INC DI
INC CX
JMP LapNhap
EndLapNhap:
@Xuong_dong
@Write 'Xau chu hoa:'
LEA DX,xau
MOV AH,9
INT 21h
INT 20h
Include PROC.ASM ;Khai bao thu vien thu tuc
code ends
End start
;Bai 43/Nhap mot mang, kiem tra mang co phai la mot day don dieu hay khong? (Su dung PROC.ASM va MYLIB.MAC).
include MYLIB.MAC ;Khai bao thu vien MACRO
Code Segment
org 100h
assume cs:code
start: JMP over
A DW 20 DUP (0)
N DW ?
Over:
@write 'Nhap so phan tu='
Call Nhap_so
MOV N,AX
XOR BX,BX
XOR CX,CX
@Xuong_dong
LapNhap:
@Write 'Nhap so thu '
MOV AX,CX
Call IN_SO
@Write ':'
Call Nhap_so
MOV A[BX],AX
@Xuong_dong
ADD BX,2
INC CX
CMP CX,N
JB LAPNhap
XOR BX,BX
XOR DX,DX
DEC CX
CMP N,2
JB Thoat
MOV AX,A[BX]
CMP AX,A[BX+2]
JL Qua
INC DX
Qua:
INC DX
Lap_KTr:
MOV AX,A[BX]
CMP AX,A[BX+2]
JG Qua1
CMP DX,1
JNE Thoat
Jmp Tiep
Qua1:
CMP DX,2
JNE Thoat
Tiep:
ADD BX,2
LOOP Lap_KTr
XOR DX,DX
Thoat:
Cmp DX,0
JNE Qua2
@Write 'Day la mot day don dieu'
jmp Ketthuc
Qua2:
@Write 'Day khong phai la mot day don dieu'
Ketthuc:
INT 20h
Include PROC.ASM ;Khai bao thu vien thu tuc
code ends
End start
Bạn đang đọc truyện trên: Truyen247.Pro