1

I prompt the user for input:

mov ah, 0Ah
mov dx, OFFSET buffer
int 21h

My assignment tells me that ctrl-c should "abort the program with an appropriate error message".

I was told that int 23h is called whenever ctrl-c is called or detected. Apparently I can register my own interrupt handler via int 21h / ah=25h.

But I don't know how to make an interrupt handler, nor do I know where this is supposed to go in my code. Assistance would be appreciated, thank you in advance.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
3932695
  • 87
  • 1
  • 9
  • 1
    This question: http://stackoverflow.com/questions/7406055 has a working example of how to write and register an interrupt handler. – us2012 Oct 16 '13 at 10:59

2 Answers2

3

do followings to write your custom interrupt handler

SettingIntVector:
     mov ah,25h      ;Here set your ah register for calling Interrupt vector
     mov al,22h      ;Your Interrupt Address
     mov dx,IntHandlerCode   ;Interrupt Handler
     int 21h                 ;Dos Interrupt 



 IntHandlerCode:
    mov ah,9
    mov dx, offset our_text
     mov ah,9
    int 21h   
    iret

our_text db "new Interrupt Handler... $"

I hope this helped to figure out how stuff works. This Interrupt Just write "new Interrupt Handler " to screen

Yasin Fatullayev
  • 137
  • 1
  • 11
  • Doesn't the interrupt handler need to restore any registers it modifies? Or does the `int 21h` API put a wrapper around your code that does that for you? (I'm guessing it doesn't, otherwise you'd return back to some DOS code that restores regs, using `ret` not `iret`. Or is there privilege switching happening here if you're returning back to DOS rather than to your own code?) Based on Martin's answer, your function's address goes directly into the IDT, so you should need to save/restore regs. – Peter Cordes Apr 11 '16 at 03:34
  • 1
    @PeterCordes It's essentially an API entry point, or more accurately an API callback. In this case the interrupt is required to preserve all registers, except the carry flag which is used as a return value. Since this code preserves the carry flags the interrupted MS-DOS function is restarted. Another problem with this handler is that it could be called recursively, if CTRL-C is pressed while the message is being outputted. It should be noted that DS is used as the segment of the handler, so CS == DS must be true. Finally it changes the wrong vector, 22h instead of 23h. – Ross Ridge Apr 11 '16 at 08:28
  • @RossRidge: Thanks! Interesting to see how a non-multi-tasking OS handled things like that. Is the callback really supposed to use `iret`, though, rather than just a near or far return? Because `iret` restores `EFLAGS` from the stack, which conflicts with your description of `CF` as part of the return value. Or do callbacks have the option of returning with `iret` or `ret far 2` to pop the flags without restoring them? (Only diff I can see for real mode between `iret` and `ret far`). Also, looks like your comment would make a solid answer to the OP's question :P – Peter Cordes Apr 11 '16 at 08:41
  • @PeterCordes In this case the handler can use either IRET, RETF 2 or RETF. The later works because MS-DOS checks SP after the call to see what it popped. – Ross Ridge Apr 11 '16 at 08:51
1

As far as I know function ah=25h does nothing but writing the interrupt vector to the interrupt vector table.

This table is located at address 0000:0000 and contains segment:offset pointers to the interrupts.

This means: Function 25h would simply write the segment (value of CS) to address 0000:008E and the offset (address of your interrupt handler) to 0000:008C.

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38