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

  1.     ;MASM MODE
  2.     .386p
  3.     .model small
  4.  
  5. include  prints.ase 
  6. include  input.ase 
  7. include  mtrap.ase 
  8.  
  9. DUMPLEN = 80h
  10.     PUBLIC    dump
  11.     extrn put_pure : proc, put_msg:proc
  12.  
  13.     .data
  14. index    dd    0        ; Default for next dump
  15.  
  16.     .code
  17. ;
  18. ; Dump one line
  19. ;
  20. dumpline    PROC    
  21.     push    edx
  22.     push    ebx                ; EBX MUST be on second of stack
  23.     push    ecx            ; ECX MUST be on top of stack
  24.     sub    eax,eax
  25.     mov    al,bl          ; AL = lower byte of address
  26.     and    al,15        ; AL = lower nibble
  27.     mov    ecx,16        ; Total bytes to dump
  28.     jz    short doline    ; Go do hexdump if start of line = 0
  29.     neg    al        ; Else calculate number of bytes in line
  30.     add    al,16        ;
  31.     mov    ecx,eax        ; To ECX
  32.  
  33. doline:
  34.     sub    [esp],ecx    ; Decrement count which is on stack
  35.     add    [esp+4],ecx    ; Increment address which is on stack
  36.     mov    al,16        ; Get count of amount to space over
  37.     sub    al,cl        ;
  38.     jz    short puthex    ; Don't space over any, just put out hex
  39.  
  40.     push    ecx        ; Else ecx = spacecount * 3
  41.     mov    ecx,eax        ;
  42.     add    ecx,ecx        ;
  43.     add    ecx,eax        ;
  44. blanklp1:
  45.     call    printspace      ; Dump spaces
  46.     loop    blanklp1    ;
  47.     pop    ecx
  48.  
  49. puthex:                         ; Save count and address for ASCII dump
  50.     push    ecx        ;
  51.     push    esi        ;
  52. hexlp:
  53.     call    printspace    ; Print a space
  54.     mov    al,[esi]    ; Get the byte
  55.     inc    esi        ; Increment the address pointer
  56.     call    printbyte    ; Print byte in hex
  57.     loop    hexlp        ; Loop till done
  58.     pop    esi        ;
  59.     pop    ecx        ;
  60.  
  61.     call    printspace    ; Print two spaces to seperate ASCII dump
  62.     call    printspace    ;
  63.  
  64.     sub    eax,eax        ; Calculate amoun to space over
  65.     mov    al,16        ;
  66.     sub    al,cl        ;
  67.     jz    short putascii    ; None to space over, put ascii
  68.     push    ecx        ; ECX = space value
  69.     mov    ecx,eax
  70. blanklp2:
  71.     call    printspace    ; Space over
  72.     loop    blanklp2    ;
  73.     pop    ecx        ;
  74.  
  75. putascii:
  76.     mov    dl,[esi]    ; Get char
  77.     inc    esi        ; Increment buffer
  78.     call    put_pure
  79.     loop    putascii
  80.     pop    ecx        ; Get count from stack
  81.     pop    ebx        ; Get address from stack
  82.     pop    edx        ; Restore EDX
  83.     ret
  84. dumpline    ENDP    
  85. ;
  86. ; Main DUMP routine
  87. ;
  88. dump    PROC    
  89.     call    PageTrapErr    ; Enable error on page trap
  90.     mov    ecx,DUMPLEN    ; Default amount to dump
  91.     call    WadeSpace    ; Wade to end of spaces
  92.     cmp    al,13        ; If no numbers, we just use the old default
  93.     jz    short atIndex    ;
  94.     call    ReadAddress    ; Else read start address
  95.     jc    dudone        ; Quit on error
  96.     call    WadeSpace    ; Wade through spaces
  97.     cmp    al,13        ; If no numbers, just use the default
  98.     jz    short dodump    ;
  99.     call    ReadNumber    ; Else read end offset
  100.     jc    short dudone    ;
  101.     sub    eax,ebx        ; Calculate length of dump
  102.     mov    ecx,eax        ;
  103.     jmp    short dodump    ; Go do dump
  104. atIndex:
  105.     mov    ebx,[index]    ; Assume we want to dump from last index
  106. dodump:
  107.     
  108.     mov    esi,ebx
  109. dumplp:
  110.     push    ebx        ;
  111.     mov    ebx,offset CRLF
  112.     call    put_msg
  113.     pop    ebx        ;
  114.     mov    eax,ebx        ;
  115.     and    eax,0fffffff0h  ; Address low nibble = 0
  116.     call    printdword    ; Print address
  117.     call    dumpline    ; Dump a line
  118.     or    ecx,ecx        ; Continue while count > 0
  119.     jg    dumplp        ;
  120.     mov    [index],ebx    ; Save new index value
  121.     clc            ; No errors
  122. dudone:
  123.     pushfd            ; Save error flag
  124.     call    PageTrapUnerr    ; Disable page traps
  125.     popfd            ; Restore error flag
  126.     ret
  127. dump    ENDP    
  128. END