home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / DUMP.ASM < prev    next >
Assembly Source File  |  1990-10-04  |  4KB  |  127 lines

  1. ; DUMP.ASM: Dump Utility
  2.  
  3. ; ------Macros--------------------------
  4.  
  5. doscall macro   x
  6.         mov     ah,x
  7.         int     21h
  8.         endm
  9.  
  10. outchar macro   x
  11.         mov     dl,x
  12.         doscall 2
  13.         endm
  14.  
  15. code    segment
  16.         org     100h
  17.         assume  cs:code,ds:code
  18. start:  jmp     begin
  19.  
  20. ; ------Variables----------------------
  21.  
  22. fcount  dw      0
  23. eofflag db      0
  24. fnfmsg  db      'File not Found$'
  25. hexchar db      '0123456789ABCDEF'
  26.  
  27. ; ----- main loop -------------
  28.  
  29. begin:  mov     dx,5ch          ; fcb prepared by DOS
  30.         doscall 0fh             ; open file
  31.         cmp     al,0ffh         ; if ffh then 
  32.         jne     d1              ; file not found
  33.         mov     dx,offset fnfmsg
  34.         doscall 9               ; display message
  35.         jmp     exit            ; end
  36.  
  37. ; if file is present begin by reading 
  38. ; data in DTA at offset 80h
  39.  
  40. d1:     mov     dx,5ch
  41.         doscall 14h             ; read data block (128 bytes)
  42.         cmp     al,1            ; if end of file
  43.         je      exit            ; end
  44.         cmp     al,3            ; if partial block
  45.         jne     d2              ; display file and end
  46.         inc     eofflag         
  47. d2:     call    outrec          ; display 128 bytes of DTA
  48.         cmp     eofflag,1       ; EOF?
  49.         jne     d1              ; if not, jump to top
  50. exit:   int     20h
  51.  
  52. outrec  proc    near
  53.         mov     bp,80h          ; bp points to beginning of DTA
  54. or1:    call    outcnt
  55.         call    outhex
  56.         call    outasci
  57.         outchar 13
  58.         outchar 10
  59.         add     bp,16           ; position base pointer
  60.         add     fcount,16       ; and file counter
  61.         cmp     bp,100h         ; finished after 128 bytes 
  62.         jne     or1
  63.         outchar 13
  64.         outchar 10
  65.         ret
  66. outrec  endp
  67.  
  68. outcnt  proc    near        ; outcnt displays the memory address
  69.         mov     ax,fcount       ; in hex as MSB LSB:
  70.         mov     al,ah           ; switch for display
  71.         call    outbyte 
  72.         mov     ax,fcount  
  73.         call    outbyte
  74.         outchar ':'             ; separate with :
  75.         outchar ' '
  76.         ret
  77. outcnt  endp
  78.  
  79. outhex  proc    near        ; outhex displays a hex dump
  80.         mov     si,0  
  81. oh1:    mov     al,[bp+si]      ; read byte
  82.         call    outbyte         ; and display
  83.         outchar ' '
  84.         inc     si
  85.         cmp     si,8            ; add extra space between 
  86.         jne     oh2             ; bytes 7 and 8 for clarity
  87.         outchar ' '
  88. oh2:    cmp     si,16           ; if si = 16 then return
  89.         jne     oh1
  90.         outchar ' '             ; separate with a space
  91.         ret
  92. outhex  endp
  93.  
  94. outasci proc    near        ; outasci displays the ASCII characters
  95.         mov     si,0            ; prepare oa1 loop
  96. oa1:    mov     dl,[bp+si]      ; read character
  97.         and     dl,7fh          ; set MSB = 0
  98.         cmp     dl,20h          ; if char can be printed then 
  99.         jae     oa2             ; jump to oa2
  100.         mov     dl,'.'        ; else print .
  101. oa2:    doscall 2               ; print character
  102.         inc     si              
  103.         cmp     si,16        ; when performed 16 times, end
  104.         jne     oa1
  105.         ret
  106. outasci endp
  107.  
  108. outbyte proc    near        ; output char. to screen
  109.         mov     bx,offset hexchar
  110.         push    ax 
  111.         and     al,0f0h    
  112.         mov     cl,4     
  113.         rol     al,cl  
  114.         xlat               ; translate into hex
  115.         mov     dl,al  
  116.         doscall 2        ; display
  117.         pop     ax   
  118.         and     al,0fh
  119.         xlat            ; translate into hex
  120.         mov     dl,al
  121.         doscall 2        ; display
  122.         ret
  123. outbyte endp
  124.  
  125. code    ends
  126.         end     start
  127.