实验4 8086标志寄存器及中断
实验任务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
答:不能替换,因为add会改变CF的值,使进位出错。
实验截图:

实验任务2
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
实验截图:

问题:
(1)输入字符到al,存入[si],和#比较,相等进入next,不相等继续循环。
(2)输出换行符。
(3)输出字符si次,由于最后一次si没有增加,最后的#不输出。
实验任务3
源代码:
assume ds:data, cs:code, ss:stack
data segment
x dw 91, 792, 8536, 65535, 2021, 0
len equ $ - x
data ends
stack segment
db 16 dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 16
mov di, offset x
mov cx, len/2 ; len/2处理数量
foreach:
mov ax, word ptr ds:[di]
push cx
call printNumber
pop cx
mov ah, 2
mov dl, 20h
int 21h
add di, 2
loop foreach
mov ah, 4ch
int 21h
;ax:输入数字
printNumber:
mov bx, 0
num:
mov dx, 0
mov bp, 10
div bp;dxax/bp得ax商 dx余数
push dx;余数 即末位
inc bx;存储数字位数
cmp ax, 0
je next
jmp num
next:
mov cx, bx;数字位数
print:
pop dx
add dl, 30h;转成为字符
mov ah, 2
int 21h
loop print
ret
code ends
end start
实验截图:

实验任务4
源代码:
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:
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:
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
源代码:
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
实验截图:

实验任务6
实验截图:

通过编译连接运行task6_1.asm和task6_2.asm后可以看到,屏幕底部出现了绿色的"welcome to 2049!",说明42号中断程序被成功调用。
浙公网安备 33010602011771号