2010-07-21 4 views
0

다음 코드 조각을 게시 할 때이 코드의 기본 목적은 트랩 플래그를 1로 설정하면 그 후에 화면에 문자 z를 트랩으로 인쇄 할 때입니다. 플래그가 설정되면 프로그램에서 하나의 명령과 트랩을 실행해야합니다. F2 키의 스캔 코드를 볼 수 있으므로 F2 키를 누르면 무한 루프가있는 간단한 트랩 ISR이 작성됩니다. 프로그램에서 kbisr이라는 키보드 isr. 이것은이 프로그램에서 얻고 자하는 기능이지만,이 코드를 확인하고 그것을 잘못하고 있는지 말해주십시오.Intel IAPX88 프로세서, 트랩 ISR

mov word[es:1*4+1],cs 

그것은해야한다 : 여기 당신은이 라인의 잘못이있어

[org 0x100] 
jmp start 

flag: db 0 

kbisr: push ax 
push cs 
pop ds 

in al,0x60 ; reading keyboard port 
cmp al,60 ; comparing it with scan code of F2 
jne skip ; if not F2 then do nothing 

mov byte[flag],1 


skip: pop ax 

; signlaing end of interrupt 
mov al,0x20 
out 0x20,al 
iret 

; subroutin to clear the screen 
clrscr: push ax 
push bx 
push es 
push di 
push cx 

mov ax,0xb800 
mov es,ax 
mov cx,4000 
mov ax,0x0720 
rep stosw 
pop cx 
pop di 
pop es 
pop bx 
pop ax 
ret 

; the trap ISR 

trap: push ax 
push bx 
push cx 
push dx 
push es 
push ss 
push ds 
push cs 
push di 
push si 
push bp 


push cs 
pop ds ; initializing the data segment 
sti 
call clrscr 
mov byte[flag],0 
l1: cmp byte[flag],0 ; infinite loop, waiting for F2 
je l1 
pop bp 
pop si 
pop di 
pop cs 
pop ds 
pop ss 
pop es 
pop dx 
pop cx 
pop bx 
pop ax 

iret 

start: 

mov ax,0 
mov es,ax 

; hooking the trap interrupt 

mov word[es:1*4],trap 
mov word[es:1*4+1],cs 
;now hooking the keyboard interrupt 
cli 
mov word[es:9*4],kbisr 
mov word[es:9*4+2],cs 
sti 
mov cx,0xb800 
mov es,cx 
mov di,10 
mov ch,0x05 
mov cl,'z' 
;setting the trap flag to 1 
pushf 
pop bx 
or bx,0x100 
push bx 
popf 
; now trap flag is on 

mov word[es: di],cx 
add di,2 
mov word[es: di],cx 
add di,2 
;residing the program in memory after termination so this is a TSR 
mov dx,start 
add dx,15 
shr dx,4 
mov ax,0x3100 
int 0x21 

답변

0

코드입니다

mov word[es:1*4+2],cs 

편집 :

pop cs 
무엇

해야하니?

실제로, nasm이 이에 대해 불평하지 않았다는 사실이 놀랍습니다.

+0

예, 이것은 코드의 오류입니다. 그러나 수정했습니다. 그러나 F2 KEY를 누르면 오류 메시지가 나타납니다. –

+0

나를 위해, Dosbox는 불법 opcode 0F에 대한 불평을합니다. 답에. – ninjalj

+0

ok kbisr에서 먼저 cs를 푸시 한 다음 cs를 팝했습니다. 이제 오류 메시지는 없지만 화면에 문자 z가 인쇄되지 않습니다. –