Intel IAPX88处理器,陷阱ISR

发布于 2024-09-11 00:09:48 字数 1622 浏览 10 评论 0原文

我发布下面的一段代码,这段代码的基本目标是,当我将陷阱标志设置为 1 时,然后我在屏幕上打印一个字符 z,现在设置陷阱标志后,程序应该执行一个指令和陷阱,我写了一个简单的陷阱ISR,其中有一个无限循环,如果按下F2键,这个无限循环就会被打破,你可以在程序中看到键盘isr中名为kbisr的F2键的扫描代码。 这是我想从这个程序实现的功能,但它没有做到这一点,请检查此代码并告诉我我做错了什么。这是代码

[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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦亿 2024-09-18 00:09:48

您的这一行错误:

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

它应该是:

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

编辑:
应该做什么

pop cs

事实上,令我惊讶的是 nasm 没有对此提出抱怨。

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.

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