home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / inthand.asm < prev    next >
Encoding:
Assembly Source File  |  1986-09-04  |  1.9 KB  |  92 lines

  1. ; INTHAND.ASM
  2. ;
  3. ; Copyright (c) 1986 Peter W. Gofton
  4. ; Interrupt handler for IBM PC Serial i/o
  5. ; Designed to interface with Microsoft 'C'
  6. ; Compile as: MASM INTHAND;
  7. ;
  8. ;------------------------------------------------------------------------
  9.  
  10. _TEXT    SEGMENT  BYTE PUBLIC 'CODE'
  11. _TEXT    ENDS
  12.  
  13. ASSUME  CS: _TEXT, DS: NOTHING, SS:NOTHING, ES:NOTHING
  14.  
  15.  
  16. _TEXT      SEGMENT
  17.  
  18. ; Create a stack for use by the 'C' function
  19.  
  20. intstack DB 256 DUP (?)
  21.  
  22. EXTRN _myds:WORD
  23.  
  24. EXTRN _cfunct:NEAR
  25.  
  26. ;--------------------------------------------------------------------------
  27. PUBLIC _inthand
  28.  
  29. _inthand    PROC NEAR
  30. ; This function is called automatically by the interrupt mechanism.
  31. ; cfunct() must be a function which takes any necessary action such as 
  32. ; receiving or transmitting characters
  33.  
  34. ; We know when we get here that CS is the same as the CS containing
  35. ; out 'C' code, since CS and IP were saved in the interrupt vector.
  36.  
  37. ; But DS may be anything, and the 'C' function will need it to access
  38. ; the data. So we have to restore it before calling cfunct()
  39.  
  40.  
  41.     STI            ; Enable interrupts
  42.  
  43.     PUSH    AX     ; Save all registers
  44.     PUSH    BX
  45.     PUSH    CX
  46.     PUSH    DX
  47.     PUSH    SI
  48.     PUSH    DI
  49.     PUSH    DS
  50.     PUSH    ES
  51.     
  52.     MOV    AL, 20H
  53.     OUT    20H, AL
  54.  
  55.     MOV    SI, OFFSET _myds
  56.     MOV    DS, CS:[SI]
  57.  
  58.     PUSH    SS
  59.     PUSH    CS
  60.     POP     SS
  61.     MOV     SP, offset intstack
  62.  
  63.     CALL    _cfunct             ; Call the 'C' function
  64.  
  65.     POP     SS
  66.     POP    ES                   ; Restore all registers
  67.     POP    DS
  68.     POP    DI
  69.     POP    SI
  70.     POP    DX
  71.     POP    CX
  72.     POP    BX
  73.     POP    AX
  74.  
  75.     IRET
  76.  
  77. _inthand endp
  78. ;--------------------------------------------------------------------------
  79. _TEXT    ENDS
  80.  
  81. END
  82. ;--------------------------------------------------------------------------
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. ; Figure 17.2: Interrupt Handler Gate
  90.  
  91.