一. 实验目的
1、掌握顺序和循环程序结构和设计方法;
2、熟悉在PC机上建立、汇编、连接、调试和运行8086/8088汇编语言程序的过程。
二. 实验内容
1、X、Y、Z、V均为字变量,在X、Y、Z、V字单元中存放是16位带符号数。试编写汇编语言程序完成以下功能:
①计算表达式值(V–(X*Y+Z-720))/X;
②将上述表达式运算结果整数放在SUM1单元,余数放在SUM2单元。
2、使用地址表实现如下功能:根据输入的数字1-7,分别显示相应的英文星期名,如果输入其他字符,则重新输入。
3、求一个班50名学生成绩的平均值、最大值和最小值,并将结果显示出来。
4、从键盘读入一个字符串,以Enter结束,字符串不超过60个字符,并打印该字符串;查找中间是否有自己名字拼音首字母缩写的子串。如果有,输出‘TRUE’;否则,输出‘FALSE’)。
实验一
stack segment stack
dw 512 dup(?)
stack ends
data segment
X dw 36
Y dw 20
Z dw 1
V dw 1080
sum1 dw ?
sum2 dw ?
data ends
code segment
assume cs:code,ds:data,ss:stack
start: mov ax,data
mov ds,ax
mov ax,X
mov bx,Y
Imul bx
add ax,Z
sub ax,720
mov bx,V
sub bx,ax
mov ax,bx
mov bx,X
idiv bx
mov [sum1],ax
mov [sum2],dx
push dx
mov cl,4
mov dl,ah
call dispa
mov dl,ah
call dispap
mov dl,al
call dispa
mov dl,al
call dispap
pop dx
push dx
mov ax,dx
mov dl,ah
call dispa
mov dl,ah
call dispap
mov dl,al
call dispa
mov dl,al
call dispap
pop dx
mov ah,4ch
int 21h
dispa proc
push ax
shr dl,cl
or dl,30h
cmp dl,39h
jbe lab
add dl,7
lab: mov ah,2
int 21h
mov dl,20h
mov ah,2
int 21h
pop ax
ret
dispa endp
dispap proc
push ax
and dl,0fh
or dl,30h
cmp dl,39h
jbe laba
add dl,7
laba: mov ah,2
int 21h
mov dl,20h
mov ah,2
int 21h
pop ax
ret
dispap endp
code ends
end start
;masm file.asm
;link file.obj
;file.exe
;debug file.exe
;u
;t
实验二
stack segment stack
dw 512 dup(?)
stack ends
data segment
address dw l1,l2,l3,l4,l5,l6,l7
week1 db 'Monday$'
week2 db 'Tuesday$'
week3 db 'Wednesday$'
week4 db 'Thursday$'
week5 db 'Friday$'
week6 db 'Saturday$'
week7 db 'Sunday$'
data ends
code segment
assume cs:code,ds:data,ss:stack
start: mov ax,data
mov ds,ax
mov ax, stack
mov ss, ax
mov ah,1
int 21h
mov bl,al
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov al,bl
sub al,'0'
dec al
mov ah,0
mov bx,ax
shl bx,1
jmp address[bx]
l1: lea dx,week1
jmp next1
l2: lea dx,week2
jmp next1
l3: lea dx,week3
jmp next1
l4: lea dx,week4
jmp next1
l5: lea dx,week5
jmp next1
l6: lea dx,week6
jmp next1
l7: lea dx,week7
next1: mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
实验三
stack segment stack
dw 512 dup(?)
stack ends
data segment
buffer db 20
db 0
db 20 dup(0)
minx db ?
maxx db ?
avgx db ?
num dw ?
string db 'Enter the grade of student:',13,10,'$'
minni db 'The min of grade is:',13,10,'$'
maxxa db 'The max of grade is:',13,10,'$'
avggv db 'The avg of grade is:',13,10,'$'
data ends
code segment
assume cs:code,ds:data,ss:stack
start: mov ax,data
mov ds,ax
mov bx,0
mov cx,50
mov [minx],64h
mov [maxx],00h
again: lea dx,string
mov ah,9
int 21h
mov ah,0ah
mov dx,seg buffer
mov ds,dx
mov dx,offset buffer
int 21h
push bx
push ax
call stoi
pop ax
pop bx
add bx,[num]
mov ax,[num]
cmp al,[minx]
jb minnx
fuck: cmp al,[maxx]
ja maxxx
jmp done
minnx: mov [minx],al
jmp fuck
maxxx: mov [maxx],al
done: mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
loop again
mov ax,bx
mov bx,32h
mov dx,0
div bx
mov bx,ax
lea dx,avggv
mov ah,9
int 21h
mov ax,bx
call dis
lea dx,minni
mov ah,9
int 21h
mov al,[minx]
call dis
lea dx,maxxa
mov ah,9
int 21h
mov al,[maxx]
call dis
mov ah,4ch
int 21h
stoi proc
mov DX,0
mov bx,10
mov SI,2
mov [num],0
mov AX,0
LOP: MOV AL,buffer[SI]
CMP AL,0DH
JE FINAL
SUB AL,30H
CMP [num],0
JE DO_DEAL
PUSH AX
MOV AX,[num]
MUL bx
MOV [num],AX
POP AX
DO_DEAL:
ADD [NUM],AX
MOV AX,0
INC SI
JMP LOP
FINAL:
RET
stoi ENDP
dis proc
push dx
mov cl,4
;mov dl,ah
;call dispa
;mov dl,ah
;call dispap
mov dl,al
call dispa
mov dl,al
call dispap
pop dx
push ax
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
pop ax
ret
dis endp
dispa proc
push ax
shr dl,cl
or dl,30h
cmp dl,39h
jbe lab
add dl,7
lab: mov ah,2
int 21h
pop ax
ret
dispa endp
dispap proc
push ax
and dl,0fh
or dl,30h
cmp dl,39h
jbe laba
add dl,7
laba: mov ah,2
int 21h
pop ax
ret
dispap endp
code ends
end start
实验四
stack segment stack
dw 512 dup(?)
stack ends
data segment
string db 61
db 0
db 61 dup(0)
names db 6
db 0
db 6 dup(0)
strx db 'Enter string:',13,10,'$'
namesd db 'Enter you name:',13,10,'$'
true db 'TRUE',13,10,'$'
false db 'FALSE',13,10,'$'
print db 'Print: ',13,10,'$'
data ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov dx,data
mov ds,dx
lea dx,strx
mov ah,9
int 21h
mov ah,0ah
mov dx,seg string
mov ds,dx
mov dx,offset string
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov al,string[1]
add al,2
mov ah,0
mov si,ax
mov string[si],'$'
lea dx,print
mov ah,9
int 21h
lea dx,string[2]
mov ah,9
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
lea dx,namesd
mov ah,9
int 21h
mov ah,0ah
mov dx,seg names
mov ds,dx
mov dx,offset names
int 21h
mov dl,10
mov ah,2
int 21h
mov dl,13
mov ah,2
int 21h
mov ax,ds
mov es,ax
lea si,string[2]
lea di,names[2]
mov dx,si
mov bx,di
mov al,string[1]
s: mov cl,names[1]
mov ch,0
repz cmpsb
jz next
inc dx
mov si,dx
mov di,bx
dec al
jnz s
lea dx,false
mov ah,9
int 21h
jmp least
next: lea dx,true
mov ah,9
int 21h
least: mov ah,4ch
int 21h
code ends
end start