assembly - 如何在汇编8086中显示中断向量表?
问题描述
我想在程序集 8086 中的代码中显示中断向量表,然后我希望它在第一个空闲向量处停止。
问题是:查看中断向量表并确定第一个空闲向量。
我知道表的第一个向量的地址是0000h,所以我尝试将cs
段寄存器设置为它,我做不到?我试过了:mov cs,0
但mov bx,0
mov cs,bx
没有奏效。
然后我又试call cs:offset 0000h
了一次还是不行。那么我该怎么做呢?
解决方案
问题是:查看中断向量表并确定第一个表空闲向量
这是一个双重问题。
要显示所涉及的数字,您可以阅读使用 DOS 显示数字。
要找到包含 0:0 的中断向量表 (IVT) 中的第一个插槽,您可以使用以下代码:
xor si, si ; Set DS:SI to the start of the IVT
mov ds, si
cld ; Have LODSW increment (by 2) the SI register
Again:
lodsw ; The offset part of a vector
mov dx, ax
lodsw ; The segment part of a vector
or ax, dx
jz Found ; If both parts are zero, then their OR will set ZF=1 (Zero Flag)
cmp si, 1024
jb Again ; Repeat until the end of the IVT which is at address 1024
NotFound:
...
jmp ..
Found:
sub si, 4 ; -> DS:SI is the address of the first slot containing 0:0
包含 0:0 的 IVT-slot 肯定是空闲的,但它是否是第一个空闲的时隙并不一定正确。在Find a free interrupt slot中@Margaret Bloom 的回答中阅读更多相关信息。
[编辑]
一种更优雅的解决方案,它也更短但速度稍慢,并且减少了一个寄存器(DX
不使用寄存器):
xor si, si ; Set DS:SI to the start of the IVT
mov ds, si
Again:
mov ax, [si] ; The offset part of a vector
or ax, [si+2]; The segment part of a vector
jz Found ; If both parts are zero, then their OR will set ZF=1 (Zero Flag)
add si, 4
cmp si, 1024
jb Again ; Repeat until the end of the IVT which is at address 1024
NotFound:
...
jmp ..
Found:
; -> DS:SI is the address of the first slot containing 0:0
这就是@Peter Cordes 在评论中提出的想法。它在循环中慢了 1 个时钟,但如果我们用 and 替换 and 指令,我们可以减少2add si, 2
个sub si, 2
字节:inc si
inc si
dec si
dec si
xor si, si ; Set DS:SI to the start of the IVT
mov ds, si
cld
Again:
lodsw ; The offset part of a vector
or ax, [si] ; The segment part of a vector
jz Found ; If both parts are zero, then their OR will set ZF=1 (Zero Flag)
add si, 2
cmp si, 1024
jb Again ; Repeat until the end of the IVT which is at address 1024
NotFound:
...
jmp ..
Found:
sub si, 2 ; -> DS:SI is the address of the first slot containing 0:0
推荐阅读
- java - 以下代码段不会产生预期结果
- postgresql - postgres_fdw:可以将数据推送到外部服务器以供加入吗?
- sql - 我可以在同一查询中单独选择列值并作为一个连接选择列值并避免冗余代码吗?
- ionicsecurity - 离子安全 SDK 版本
- c# - unknown_error_in_process 通过 IDebugControl 但通过 WinDBG 解决
- hibernate - 违反参照完整性约束 - 如何在同一事务中引用实体之前强制写入被引用实体?
- android - MPAndroidChart:x 轴上的日期 - 粘性月份和年份
- c# - 使用 Roslyn 获取公共函数
- powershell - ForEach 循环的输出列表
- javascript - 在jquery中添加和删除div不起作用