Page 1 of 1

isr

Posted: Fri Oct 10, 2008 3:33 am
by mobruan
Hi, why this code didnt work? It supposed to interrupt and print a 'a' on the screen.
thanks

mov ax, 0x07c0
mov ds, ax

mov ax, 0x07c0 ;selector
mov [36], word ax
lea ax, [isr] ;offset
mov [38], word ax

mov [12], word 255 ; lidt limit
mov [14], word 0 ; start of idt
mov [16], word 0

lidt [12]

int 9 ; interrupt

jmp $

isr:
mov ax, 0xb800
mov ds, ax

mov [0x0000], byte 0x61 ;print 'a'
mov [0x0001], byte 01110010b

Re: isr

Posted: Fri Oct 10, 2008 4:03 am
by Combuster
You're not writing to the IVT, but to some random place in your code.

Re: isr

Posted: Fri Oct 10, 2008 4:25 am
by CodeCat
I assume you're using real mode here, so why exactly are you using 'lidt'? I thought the idt was hardwired at address 0 in real mode.

And you also need an 'iret' at the end of your isr.

Re: isr

Posted: Fri Oct 10, 2008 7:06 am
by mobruan
Hi, i dont understood combuster.

Re: isr

Posted: Fri Oct 10, 2008 7:21 am
by neon
Hi, i dont understood combuster.
The current data segment that is being used is 0x7c0, but the ivt is at address 0. You need to use a null segment when writing the interrupt entry in the ivt in order for your code to work.

Also, your use of LIDT is error prone here and not needed.

Re: isr

Posted: Fri Oct 10, 2008 8:16 am
by mobruan
I do the following and the computer resets:

mov ax, word 0x0000
mov ds, ax

mov ax, 0x07c0
mov [36], word ax
lea ax, [isr]
mov [38], word ax

int9

jmp $

isr:
mov ax, 0xb800
mov ds, ax

mov [0x0000], byte 0x61
mov [0x0001], byte 01110010b

jmp $

Re: isr

Posted: Fri Oct 10, 2008 9:03 am
by ru2aqare
It should be

Code: Select all

mov ax, 0x07c0
mov [9*4+2], word ax
lea ax, [isr]
mov [9*4+0], word ax
The point is that in real mode, a far address is specified as a segment-offset pair, and the offset goes to [address+0], segment goes to [address+2].

Re: isr

Posted: Fri Oct 10, 2008 9:24 am
by mobruan
Thanks a lot, it work!
I was inverting the order of the offset and selector.