8086 汇编器,INT 16,2
我被困在这件事上,我想看看是否按下了右移按钮,所以我有这个汇编代码:
mov ah,2
int 16h ;calling INT 16,2 - Read Keyboard Flags interrupt
mov ah,10000000b
shl al,7
and al,10000000b
cmp al,ah ;check if first bit is 1
je rshift
jmp final
rshift:
mov ah,9
lea dx,rsh ;rsh is a string that says that "right shift button has been pressed"
int 21h
jmp final
final: ; quit program
mov ax,4c00h
int 21h
为什么它不工作?,我认为问题是 int 16,2 不能正常工作,如果是的话这是为什么? 这是 INT 16,2 应该做的事情:
AH = 02
on return:
AL = BIOS keyboard flags (located in BIOS Data Area 40:17)
|7|6|5|4|3|2|1|0| AL or BIOS Data Area 40:17
| | | | | | | `---- right shift key depressed
| | | | | | `----- left shift key depressed
| | | | | `------ CTRL key depressed
| | | | `------- ALT key depressed
| | | `-------- scroll-lock is active
| | `--------- num-lock is active
| `---------- caps-lock is active
`----------- insert is active
我从未看到该消息,我在调试中查看了 AL 寄存器,在我调用 INT 16,2 后它似乎没有改变。我正在运行 Win 7在 x86 架构上,我正在使用 tasm
I got stuck at this thing,I want to see if right shift button has been pressed,so I have this assambler code:
mov ah,2
int 16h ;calling INT 16,2 - Read Keyboard Flags interrupt
mov ah,10000000b
shl al,7
and al,10000000b
cmp al,ah ;check if first bit is 1
je rshift
jmp final
rshift:
mov ah,9
lea dx,rsh ;rsh is a string that says that "right shift button has been pressed"
int 21h
jmp final
final: ; quit program
mov ax,4c00h
int 21h
why is it not working ?,I think the problem is that int 16,2 is not working properly,if so why is that?
here is what INT 16,2 is supposed to do:
AH = 02
on return:
AL = BIOS keyboard flags (located in BIOS Data Area 40:17)
|7|6|5|4|3|2|1|0| AL or BIOS Data Area 40:17
| | | | | | | `---- right shift key depressed
| | | | | | `----- left shift key depressed
| | | | | `------ CTRL key depressed
| | | | `------- ALT key depressed
| | | `-------- scroll-lock is active
| | `--------- num-lock is active
| `---------- caps-lock is active
`----------- insert is active
I never see the message,I've looked at the AL register in debug and it doesn't seem to change after I call INT 16,2.I'm running Win 7 on a x86 arhitecture,and I'm working with tasm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你如何测试这个?
出于好奇,我做了一个简单的程序(代码如下)。在 Windows 控制台下运行时,它检测到左移 (
Result: 2
),但从未检测到右移(预期Result: 1
,但只得到Result: 0< /代码>)。
当在纯 DOS 下(在 VMWare 中)运行时,它可以正确显示所有组合(0 到 3)。
所以它似乎是 NTVDM(Windows DOS 模拟)的一个工件,尽管我没有任何来源可以引用。
我的代码:
How are you testing this?
Out of curiosity, i made a simple program (code below). When run under Windows console, it detects left shift (
Result: 2
) but never detects right shift (expectedResult: 1
, but only gotResult: 0
).When run under pure DOS (in VMWare), it correctly displays all combinations (0 to 3).
So it seems to be an artifact of NTVDM (Windows DOS emulation), though I don't have any sources to cite.
My code:
您应该能够通过执行以下操作来清理您的支票:
you should be able to clean up your check by doing :
我无法解释为什么你的代码不起作用,但你可以替换
为
which 做同样的事情并且更惯用,如果汇编中有这样的东西。
编辑:
正如 Michael 在下面的评论中指出的那样,如果使用
test
指令,则需要反转条件跳转。当且仅当al
ANDC
的按位与为零时,test al, C
才设置 ZF。I cannot explain why your code isn't working, but you can replace
by
which does the same thing and is more idiomatic, if there is such a thing as an idiom in assembly.
EDIT:
As Michael points out in the comment below, you need to reverse the conditional jump if you use the
test
instruction.test al, C
sets ZF if and only the bitwise and ofal
ANDC
is zero.