8086 汇编器,INT 16,2

发布于 2024-08-10 18:13:53 字数 1044 浏览 7 评论 0原文

我被困在这件事上,我想看看是否按下了右移按钮,所以我有这个汇编代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月打碎记忆 2024-08-17 18:13:53

你如何测试这个?

出于好奇,我做了一个简单的程序(代码如下)。在 Windows 控制台下运行时,它检测到左移 (Result: 2),但从未检测到右移(预期 Result: 1,但只得到 Result: 0< /代码>)。

当在纯 DOS 下(在 VMWare 中)运行时,它可以正确显示所有组合(0 到 3)。

所以它似乎是 NTVDM(Windows DOS 模拟)的一个工件,尽管我没有任何来源可以引用。

我的代码:

.model small

.code

start:
    mov ax, seg msg
    mov ds, ax

    mov ah, 2
    int 16h

    and al,3        ; get two lower bits - both SHIFTs
    add digit, al   ; convert to decimal

    lea dx, msg
    mov ah, 9
    int 21h

    mov ax, 4c00h
    int 21h

.data

msg     db  'Result: '
digit   db  '0'
        db  13,10,'
,0

.stack
        db  16384 dup(?)

end start

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 (expected Result: 1, but only got Result: 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:

.model small

.code

start:
    mov ax, seg msg
    mov ds, ax

    mov ah, 2
    int 16h

    and al,3        ; get two lower bits - both SHIFTs
    add digit, al   ; convert to decimal

    lea dx, msg
    mov ah, 9
    int 21h

    mov ax, 4c00h
    int 21h

.data

msg     db  'Result: '
digit   db  '0'
        db  13,10,'
,0

.stack
        db  16384 dup(?)

end start
残月升风 2024-08-17 18:13:53

您应该能够通过执行以下操作来清理您的支票:

test al,1
jnz rshift

you should be able to clean up your check by doing :

test al,1
jnz rshift
安静被遗忘 2024-08-17 18:13:53

我无法解释为什么你的代码不起作用,但你可以替换

mov ah,10000000b
shl al,7 
and al,10000000b
cmp al,ah         ;check if first bit is 1

test al, 1

which 做同样的事情并且更惯用,如果汇编中有这样的东西。

编辑:
正如 Michael 在下面的评论中指出的那样,如果使用 test 指令,则需要反转条件跳转。当且仅当 al AND C 的按位与为零时,test al, C 才设置 ZF。

I cannot explain why your code isn't working, but you can replace

mov ah,10000000b
shl al,7 
and al,10000000b
cmp al,ah         ;check if first bit is 1

by

test al, 1

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 of al AND C is zero.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文