实验4 8086标志寄存器及中断
汇编实验4
1.实验任务1
task4_1
assume cs:code, ds:data
data segment
x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h
y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h
data ends
code segment
start:
mov ax, data
mov ds, ax
mov si, offset x
mov di, offset y
call add128
mov ah, 4ch
int 21h
add128:
push ax
push cx
push si
push di
sub ax, ax
mov cx, 8
s: mov ax, [si]
adc ax, [di]
mov [si], ax
inc si
inc si
inc di
inc di
loop s
pop di
pop si
pop cx
pop ax
ret
code ends
end start
① line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?
add si, 2
add di, 2
不能,使用add进位寄存器CF的值会发生变化
② 在debug中调试,观察数据段中做128位加之前,和,加之后,数据段的值的变化。

2.实验任务2
task4_2.asm
assume cs:code, ds:data
data segment
str db 80 dup(?)
data ends
code segment
start:
mov ax, data
mov ds, ax
mov si, 0
s1:
mov ah, 1
int 21h
mov [si], al
cmp al, '#'
je next
inc si
jmp s1
next:
mov ah, 2
mov dl, 0ah
int 21h
mov cx, si
mov si, 0
s2: mov ah, 2
mov dl, [si]
int 21h
inc si
loop s2
mov ah, 4ch
int 21h
code ends
end start

运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结
果。结合运行结果,理解代码并回答问题:
① 汇编指令代码line11-18,实现的功能是?
从键盘上读取输入的字符,并保存到ds:[si],如果是#,就转跳至标号next处执行;否则si + 1并继续读入下一个字符。
② 汇编指令代码line20-22,实现的功能是?
打印换行符
③ 汇编指令代码line24-30,实现的功能是?
打印字符串,并且不会把#打出来
3.实验任务3
task3.asm代码如下:
task4_3.asm
assume ds:data, cs:code, ss:stack
data segment
x dw 91, 792, 8536, 65535, 2021, 0
len equ $ - x
data ends
stack segment
dw 8 dup(?)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 16
mov cx, len/2
print:
mov ax, word ptr ds:[di]
add di, 2
push cx
call printNumber
call printSpace
pop cx
loop print
mov ah, 4ch
int 21h
; 子程序: printNumber
; 功能: 打印数字
; 入口参数:
; 寄存器ax (待输出的数据 --> ax)
; 局部变量说明:
; bx -> 存储数字字符个数
printNumber:
mov bx, 0
; getEach循环: 获取每一位,然后压入栈中
getEach:
; 除数放在16位寄存器bp中
mov bp, 10
mov dx, 0
div bp
push dx
inc bx
mov cx, ax
inc cx
loop getEach
; 打印数字
mov cx, bx
printEach:
pop dx
add dl, 30h
mov ah, 2
int 21h
loop printEach
ret
; 子程序: printSpace
; 功能: 打印空格
printSpace:
mov ah, 2
mov dl, 20h
int 21h
ret
code ends
end start

4.实验任务4
task4.asm代码如下:
task4.asm
assume cs:code,ds:data
data segment
str db "assembly language, it's not difficult but tedious"
len equ $ - str
data ends
stack segment
db 8 dup(?)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov si, 0
mov cx, len
call strupr
call printStr
mov ax, 4c00h
int 21h
; 子程序 strupr
; 功能: 将包含任意字符的字符串中的小写字母变成大写
; 入口参数
; (ds:si) 字符串首地址的段地址和偏移地址分别送至ds和si
; (cx) 字符串的长度
strupr:
push cx
push si
transform:
mov al, ds:[si]
cmp al, 97
jl continue
cmp al, 122
jg continue
and al, 0dfh
mov ds:[si], al
continue:
inc si
loop transform
pop si
pop cx
ret
; 子程序 printStr
; 功能: 打印字符串
; 入口参数
; (ds:si) 字符串首地址的段地址和偏移地址分别送至ds和si
; (cx) 字符串的长度
printStr:
push cx
push si
print:
mov ah, 2
mov dl, ds:[si]
int 21h
inc si
loop print
pop si
pop cx
ret
code ends
end start

5.实验任务5
task4_5.asm
assume cs:code, ds:data
data segment
str1 db "yes", '$'
str2 db "no", '$'
data ends
code segment
start:
mov ax, data
mov ds, ax
mov ah, 1
int 21h
mov ah, 2
mov bh, 0
mov dh, 24
mov dl, 70
int 10h
cmp al, '7'
je s1
mov ah, 9
mov dx, offset str2
int 21h
jmp over
s1: mov ah, 9
mov dx, offset str1
int 21h
over:
mov ah, 4ch
int 21h
code ends
end start

程序的功能是?
判断输入的字符是否为7,如果为7则输出yes,否则输出no。
6.实验任务6
运行42号中断程序:
通过编译连接运行task6_1.asm和task6_2.asm后可以看到,屏幕底部出现了绿色的"welcome to 2049!",说明42号中断程序被成功调用。

实验总结
to be continued......

浙公网安备 33010602011771号