Hi i have redirected divide overflow interrupt to point at my custom created interrupt which prints ‘hello man here i am’ on the screen, instead it print weird ascii characters. Can someone tell me why? here is the code
[ORG 100h]
jmp start
message: dw 'hello man here i am'
prntstr: push ax
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
push cs
pop ds
mov ah, 0x13
mov al, 1
mov bh, 0
mov bl, 7
mov dx,0x0a03
mov cx,11
push cs
push es
mov bp,message
int 0x10
pop es
pop ds
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
tsr: mov ah, 0
int 0x16
call prntstr
iret
;mov ah,4ch
;mov al, 6
;int 0x21
;iret
divs: mov ax,0x8569
mov dl,2
div dl
ret
start: xor ax,ax
mov es,ax
mov word[es:0*4], tsr
mov [es:0*4+2],cs
call divs
mov ax,0x4c00
int 0x21
one more thing i do not understand about the code is where i set offset at es:0*4 — i assument that 00 is the location of the divide overflow interrupt? what is the 0*4 for coz anything multiplied by zero would mean the same, so why the 4 ? thanks in advance
As to you weird character problems, I think:
should be:
Otherwise:
essegment register is not set up fores:bpto point to the message correctly. It will print whatever is at offsetmessagein the segmenteswas pointing to when your interrupt fired rather than in the code segment where your actual message is.For the
0*4issue, I’m not sure. It’s been a while since I did x86 but I know you can scale indirect addressing modes such as with:to ensure the correct memory locations are accessed. This scaled
edxup to the correct value before adding to thedwarraybase address.I don’t think that was needed for immediate offsets though, so I suspect it was just boilerplate code for being able to change any interrupt by just replacing the
0with the relevant interrupt number.And, as an aside, you probably don’t want to be changing interrupt vectors without ensuring that interrupts are disabled during the process. If an interrupt fires after you’ve written the offset of
tsr, but before you’ve written the segment, the results will not be pretty.