实验4 8086标志寄存器及中断
任务一
task1.asm源码
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
不能。因为inc换成add有可能引起进位,导致原本计算中的adc计算错误。

任务二
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

汇编指令代码line11-18,实现的功能是?
从键盘上读取输入的字符,并保存到ds:[si],每读入一个就判断是否为#,如果是则不保存,转跳至标号next处执行;如果不是则si + 1并继续读入下一个字符。
汇编指令代码line20-22,实现的功能是?
换行。
汇编指令代码line24-30,实现的功能是?
打印字符串,并且不会把#打出来。
任务三
assume cs:code, ds:data data segment x dw 91, 792, 8536, 65521, 2021 len equ $ - x data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, 5 s: mov ax, [si] push cx call printNumber call printSpace add si, 2 pop cx loop s mov ah, 4ch int 21h printNumber: mov dx, 0 mov cx, 0 s1: mov bx, 10 div bx push dx mov dx, 0 inc cx add ax, 0 jnz s1 s2: pop dx mov ah, 2 add dl, '0' int 21h loop s2 ret printSpace: mov ah, 2 mov dl, ' ' int 21h ret code ends end start

任务四
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
assume cs:code, ds:data
data segment
str db "assembly language, it's not difficult but tedious"
len equ $ - str
data ends
code segment
start:
mov ax, data
mov ds, ax
mov cx, len
mov si, 0
s:
call strUpr
inc si
loop s
mov cx, len
mov si, 0
mov ah, 2
printStr:
mov dl, ds:[si]
int 21h
inc si
loop printStr
mov ah, 4ch
int 21h
strUpr:
mov al, byte ptr ds:[si]
cmp al, 'a'
jb back
cmp al, 'z'
ja back
sub al, 20h
mov ds:[si], al
back:
ret
code ends
end start

任务五
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则在屏幕的第24行70列处输出yes;若不为7则在屏幕的第24行70列处输出no。
任务六

软中断是中断的一种,软中断是由程序执行的中断

浙公网安备 33010602011771号