2014-04-15 11 views
1

일부 연구를 수행했지만 터미널에서 F1-F12 키를 눌러 어셈블리 프로그램을 종료하는 방법에 대한 유효한 대답을 찾을 수 없습니다. Masm32 키 누름으로 프로그램 종료

는 그래서 같은 간단한 프로그램이 있습니다

.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에 대해 들었어요,하지만 방법이 가장 간단한 예에서 구현된다? 사전에 도움을 주셔서 감사합니다.

답변

1

좋은 예는 The MASM Forum (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

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 

, 나는 F12의 키에 종료 VK_F23을 통과해야합니다. VK_F12WaitForKeyPress에 전달하고 시스템에서 어떤 일이 발생하는지 확인할 수 있습니다.