home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / DEBUG / DISPATCH.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-03-02  |  1.2 KB  |  52 lines

  1.     .386p
  2.     .model small
  3.  
  4.     PUBLIC    TableDispatch, nofunction
  5.  
  6.     .code
  7. ;
  8. ; Core dispatch routine.  Calls the subfunction indicated in AL
  9. ; and then set the return address to after the dispatch table
  10. ; This expects a subfunction code to be on the stack
  11. ;
  12. TableDispatch    PROC    
  13.     ENTER    0,0
  14.     xchg    ebx,[ebp+4]        ; xchg ret address & ebx
  15.     cmp    al,[ebx]        ; Limit check
  16.     ja    short noaction        ; Error if too big
  17.     ; Here we call the routine
  18.     push    offset finishup        ; Return address
  19.     sub    ah,ah            ; Make key a dword
  20.     cwde                ;
  21.     push    DWORD PTR [ebx + 4 * eax + 4]    ; Get code address to stack
  22.     xchg    ebx,[ebp+4]        ; put things as they were
  23.     mov    eax,[ebp + 8]        ; Get the subkey
  24.     cld                ; Assume move dir up
  25.     ret                ; Go to subroutine
  26.     
  27. noaction:
  28.     xchg    ebx,[ebp+4]        ; Put things as they were
  29.     call    nofunction        ; Register bad function error
  30. finishup:
  31.     ; Now we have to find the return address
  32.     xchg    ebx,[ebp+4]        ; Get return address
  33.     push    eax
  34.     mov    eax,[ebx]
  35.     lea    ebx,[ebx + 4 * eax + 8]    ; Get offset to return address
  36.     pop    eax
  37.     xchg    ebx,[ebp+4]        ; Xchg with orig value of ebx
  38.     LEAVE
  39.     ret    4
  40. TableDispatch    ENDP    
  41. nofunction    PROC    
  42.     mov    eax,-1            ; Ill function error
  43.     stc                ; Set carry flag
  44.     ret
  45. nofunction    ENDP    
  46. END
  47.     
  48.     
  49.     
  50.     
  51.     
  52.