home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / DEBUG / EXEC.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-06-13  |  2.7 KB  |  120 lines

  1.     .386p
  2.     .model small
  3.  
  4. include  prints.ase 
  5. include  input.ase 
  6. include  mtrap.ase 
  7. include  breaks.ase 
  8.  
  9. TRAPFLAG = 100h            ; 80386 trap enable flag
  10.  
  11.     PUBLIC go,trap, proceed
  12.  
  13.     .data
  14.     extrn dres:word, drds:word
  15.     .code
  16. ;
  17. ; Wade through spaces only
  18. ;
  19. WadeSpaceOnly    PROC    
  20.     lodsb            ; Get a char
  21.     cmp    al,' '        ; Is space
  22.     jz    WadeSpaceOnly    ; Loop if so
  23.     dec    esi        ; Else point at char
  24.     ret
  25. WadeSpaceOnly    ENDP    
  26. ;
  27. ; Execute program
  28. ;
  29. go    PROC    
  30.     Call    WadeSpaceOnly    ; Wade till address
  31.     cmp    al,13        ; CR means from this point on
  32.     jz    short dogo    ; Do it from this EIP if CR
  33.     inc    esi        ; See if is a comma
  34.     cmp    al,','        ;
  35.     jz    short dobreak    ; Only a breakpoint if so
  36.     dec    esi        ; Get the execution point
  37.     call    ReadAddress    ;
  38.     jc    goerr        ;
  39.     mov    [dreip],ebx    ; Fix CS:EIP for new routine
  40. checkbreak:
  41.     call    WadeSpaceOnly    ; Wade
  42.     cmp    al,13        ; execute if CR
  43.     jz    short dogo    ;
  44.     cmp    al,','        ; Check for comma
  45.     jnz    goerr        ; Error if not a comma
  46.     inc    esi        ; Wade to address
  47.     call    WadeSpaceOnly
  48. dobreak:
  49.     call    ReadAddress    ; Read break address
  50.     jc    goerr        ; Quit if errir
  51.     sub    eax,eax        ; Break 0
  52.     call    setbreak    ; Set the break
  53. dogo:
  54.     call    enablebreaks    ; Enable breaks
  55.     xor    eax,eax        ; Not trapping
  56.     jmp    short gotrap    ; Run the code
  57. go    ENDP    
  58. ;
  59. ; Limited procede, only traps through near and far direct calls,
  60. ; interrupts, and near calls through a register
  61. ;
  62. proceed    PROC    
  63.     mov    ebx,[dreip]    ;
  64.     mov    ah,[ebx]    ; Load the first byte of the instruction
  65.     cmp    ah,0e8h        ; Near Call?
  66.     mov    al,5        ; Yes, this is five bytes
  67.     jz    short pgo    ; And execute it
  68.     cmp    ah,09ah        ; Far call
  69.     mov    al,7        ; This one is 7 bytes
  70.     jz    short pgo    ; And execute it
  71.     cmp    ah,0cdh        ; Interrupt ?
  72.     mov    al,2        ; two bytes
  73.     jz    short pgo    ; and execute it
  74.     cmp    ah,0ceh        ; int0?
  75.     mov    al,1
  76.     jz    short pgo
  77.     mov    ax,[ebx]    ; now check for near call through reg
  78.     and    ax,0f8ffh    ;
  79.     cmp    ax,0d0ffh    ;
  80.     mov    al,2        ; two bytes
  81.     jnz    short trap    ; Not either of these, just trap
  82. pgo:
  83.     cbw            ; EAX = bytes to skip past
  84.     cwde            ;
  85.     add    ebx,eax        ; Ebx = breakpoint
  86.     sub    eax,eax        ; Use the scratch breakpoint
  87.     call    setbreak    ; Set a break
  88.     call    enablebreaks    ; Enable breakpoints
  89.     sub    eax,eax        ; No trapping
  90.     jmp    short gotrap    ; Run the code
  91. proceed    ENDP    
  92. ;
  93. ; Trap command
  94. ;
  95. trap    PROC    
  96.     mov    eax,TRAPFLAG    ; Are trapping on instruction
  97. gotrap:
  98.     mov    esp,[dresp]
  99.     or    eax,[reflags]    ; Fill stack frame with FLAGS , CS:EIP
  100.     push    eax        ;
  101.     mov    ebx,cs    ;
  102.     push    ebx        ;
  103.     push    [dreip]        ;
  104.     movzx    eax,[drds]
  105.     push    eax
  106.     mov    es,[dres]
  107.     mov    eax,[dreax]    ; Load regs
  108.     mov    ebx,[drebx]    ;
  109.     mov    ecx,[drecx]    ;
  110.     mov    edx,[dredx]    ;
  111.     mov    esi,[dresi]    ;
  112.     mov    edi,[dredi]    ;
  113.     mov    ebp,[drebp]    ;
  114.     pop    ds        ; Load DS
  115.     iretd
  116. goerr:
  117.     stc
  118.     ret
  119. trap    ENDP    
  120. end