[汇编语言] 检测点13.1
2019-08-07 本文已影响0人
耿杰
一、在上面的内容中,我们用7ch 中断例程实现loop的功能,则上面的7ch 中断例程所能进行的最大转移位移是多少?
源代码
assume cs:code
code segment
start: mov ax, 0b800h
mov es, ax
mov di, 160 * 12
mov bx, offset s - offset se
mov cx, 80
s: mov byte ptr es:[di], '!'
add di, 2
int 7ch
se: nop
mov ax, 4c00h
int 21h
code ends
end start
分析
- 1、上面代码其实就是
jmp short 标号
, 是段内短转移,修改范围是-128~127
,它向前转移时最多越过128个字节,向后转移可以最多越过127个字节。 - 2、(IP) = (IP) + 8位转移。
二、用7ch中断例程完成amp near ptr s指令的功能,用bx向中断例程传递转移位移。
应用举例:在屏幕的第12行,显示data段中以0结尾的字符串。
assume cs:code
data segment
db 'conversation', 0
data ends
code segment
begin:
mov ax, data
mov ds, ax
mov si, 0
mov ax, 0b800h
mov es, ax
mov di, 12*160
s:
cmp byte ptr [si], 0
je ok
mov al, [si]
mov es:[di], al
inc si
add di, 2
mov bx, offset s-offset ok
int 7ch
ok:
mov ax, 4c00h
int 21h
code ends
end begin
答案
assume cs:code
data segment
db 'conversation', 0
data ends
code segment
begin:
// 设置 ds:[si], es:[di]的值,利用movsb,把offset schstart的代码复制0000:0200H处
mov ax, code
mov ds, ax
mov si, offset schstart
mov ax, 0
mov es, ax
mov di, 200h
mov cx, offset schend-offset schstart
cld
rep movsb
// 设置中断向量表
setsch:
mov ax, 0
mov es, ax
mov word ptr es:[7ch*4], 200h
mov word ptr es:[7ch*4+2], 0
// 测试代码
start:
mov ax, data
mov ds, ax
mov si, 0
mov ax, 0b800h
mov es, ax
mov di, 12*160
s:
cmp byte ptr [si], 0
je ok
mov al, [si]
mov es:[di], al
inc si
add di, 2
mov bx, offset s-offset ok
int 7ch
ok:
mov ax, 4c00h
int 21h
// 7ch对应的schstart程序
schstart:
push bp
mov bp, sp
add [bp+2], bx
pop bp
iret
schend: nop
code ends
end begin