English 中文(简体)
Intel IAPX88 Processor, Trap ISR
原标题:

I am posting the following piece of code, the basic aim of this code is, when i set the trap flag to 1 then after that i am printing a character z on the screen, now as trap flag is set, the program should execute one instruction and trap, I have written a simple trap ISR in which i have an infinite loop, this infinite loop will be broken if F2 key is pressed as you can see the scan code of F2 key in keyboard isr named kbisr in the program. This is the function that i want to achieve from this program but its not doing it please check this code and tell me what i am doing wrong with it. Here is the code

[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
问题回答

You ve got this line wrong:

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

It should be:

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

EDIT: What is

pop cs

supposed to do?

Actually, it surprises me that nasm hasn t complained about this.





相关问题
List of suspected Malicious patterns

I am doing an anti-virus project by disassembling its code and analyzing it. So I want a list of the Suspected Malicious pattern codes, so I can observe which is suspected and which is not? So I want ...

Prefetch for Intel Core 2 Duo

Has anyone had experience using prefetch instructions for the Core 2 Duo processor? I ve been using the (standard?) prefetch set (prefetchnta, prefetcht1, etc) with success for a series of P4 ...

How are mutex and lock structures implemented?

I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions ...

Installing GNU Assembler in OSX

No matter how hard I google, I can t seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac. I know I can use gcc -c (Apple Clang on a Mac) to assemble .s ...

8086 assembler,INT 16,2

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,...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签