flat assembler
Message board for the users of flat assembler.

Index > Main > TUTO: How to add intrrupt handler in ur code?

Author
Thread Post new topic Reply to topic
delta67



Joined: 18 Jul 2012
Posts: 19
delta67
Hi all,
Thanks to SHOORICK, I succusfully added a handler for NMI in my program for an 8088 based SBC.

here is the suggestion of shoorick:

....do kinda this at startup (exactly after "start"):

start:
xor ax,ax
mov ds,ax ; set ds to 0. seems, ds must be 0 after reset, but i'm not sure
mov ax,nmi_handler ; suppose nmi_handler is a label of subroutine in rom
mov dx,cs
mov [8],ax
mov [8+2],dx ; now you can switch nmi to "1" to test

here is the code I tried and it works:
Code:
;=========================================
    use16
;-----------------------------------------
start:

     xor ax,ax               ; clear AX
  mov ss,ax               ; SS= 0000
  mov ds, ax              ; DS=0000       ; data segment
      mov ax,0800h
        mov sp,ax               ; Start of stak at 800h 
    
    ; init 8255
        mov al,92h ; MODE0,  A and B ports as inputs, portC output
        out 03h,al
;--------------------------------    
    ; init interrupt vector type 2 (NMI)
        mov word[ds:02h*4], INTR ; formula for this is "Interrupt*4 = offset"
 mov word[ds:02h*4+2], cs ; we must put our segment after the offset
;------------------------------------------------    
main:
       mov al,02Fh     
    out 02h, al
 
        mov cx,0FFFFh 
delay1:
        loop delay1

        
    int 02h
     jmp main
    
    
INTR:   
    mov al,01Eh     
    out 02h, al
 
        mov cx,0FFFFh  
delay2:
       loop delay2
    
    
        iret

    


Hope this helps some one ( a NEWBIE like me !!)

THANK U SHOORICK
Post 27 Jul 2012, 12:41
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
delta67,

Loading ss with mov instruction inhibits all interrupts until after the execution of the next instruction. Common idiom is to follow mov ss, «stack_seg» with mov sp, «stack_off» — to fend off accidental interrupt while its vector is half-initialized).

loop instruction checks cx after decrementing it, thus delays can be written as
Code:
        xor     cx, cx
        loop    $    
Post 28 Jul 2012, 11:42
View user's profile Send private message Reply with quote
delta67



Joined: 18 Jul 2012
Posts: 19
delta67
baldr wrote:


Loading ss with mov instruction inhibits all interrupts until after the execution of the next instruction. Common idiom is to follow mov ss, «stack_seg» with mov sp, «stack_off» — to fend off accidental interrupt while its vector is half-initialized).

loop instruction checks cx after decrementing it, thus delays can be written as
Code:
        xor     cx, cx
        loop    $    


Thanks baldr for the cool hints !
Post 28 Jul 2012, 15:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.