我做了一些研究,但仍无法通过终端按F1-F12键找到有关如何终止装配程序的有效答案。
我有一个简单的程序:
.data
prompt1 BYTE "Please Input a sentence.",0Dh,0Ah,0
.code
Main Proc
mov edx,OFFSET prompt1
call WriteString
call ReadString
exit
main ENDP
main END
我听说过这个INT16h来检查按键是否被按下,但是如何在最简单的例子中实现?感谢您的帮助。
答案 0 :(得分:1)
从MASM论坛(posting here)找到了一个很好的例子。代码不是我的,但我之前写过这样的代码。
.XCREF
.NOLIST
INCLUDE \masm32\include\masm32rt.inc
.LIST
;#########################################################################
.CODE
;*************************************************************************
_main PROC
print chr$('Press Esc to Exit'),13,10
jmp short kloop2
kloop1: INVOKE Sleep,40
kloop2: call InKyb
jz kloop1
push eax
cmp ah,0
jz kloop3
push 2020h
jmp short kloop4
kloop3: mov ah,20h
push eax
kloop4: print esp
pop edx
pop eax
push eax
print right$(uhex$(eax),4),13,10
pop eax
cmp eax,1Bh
jnz kloop2
exit
_main ENDP
;*************************************************************************
InKyb PROC
;Polled Keyboard Input - DednDave 8, 2010
;
;This function returns a keystroke in EAX if there is one in the buffer.
;If the buffer is empty, the function returns immediately.
;
;If the keyboard buffer is empty, AH = 0, AL = 0, ZF = 1.
;If the stroke is a regular key, AH = 0, AL = key char, ZF = 0.
;If the stroke is an extended key, AH = extended key, AL = E0h, ZF = 0.
;If the stroke is a function key, AH = function key, AL = 0, ZF = 0.
;
;ECX, EDX are not preserved.
call crt__kbhit
or eax,eax
jz InKyb1
call crt__getch
and eax,0FFh
jz InKyb0
cmp al,0E0h
jnz InKyb1
InKyb0: push eax
call crt__getch
pop edx
shl eax,8
or eax,edx
InKyb1: retn
InKyb ENDP
;#########################################################################
END _main
答案 1 :(得分:1)
看起来您正在使用Irvine32库。只需使用库中的ReadKey
函数:
.data
prompt1 BYTE "Please Input a sentence.",0Dh,0Ah,0
.code
Main:
mov edx,OFFSET prompt1
call WriteString
call ReadString
push VK_F23
call WaitForKeyPress
exit
WaitForKeyPress proc VKey:byte
ReadIt:
mov eax, 10
call Delay
call ReadKey
jz ReadIt
cmp ah, VKey
jne ReadIt
ret
WaitForKeyPress endp
END Main
对于我的键盘,我需要传递VK_F23
以退出 F12 按键。您可以尝试将VK_F12
传递给WaitForKeyPress
,看看系统上发生了什么