home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MEMORIA / RAMCLEAR.ZIP / RAMCLEAR.ASM next >
Encoding:
Assembly Source File  |  1986-08-12  |  2.5 KB  |  61 lines

  1. ;------------------------------------------------------:
  2. ;   Filename....:  RAMCLEAR.ASM                        :
  3. ;   Author......:  Dennis L. Dias                      :
  4. ;   Source ID...:  NAN449                              :
  5. ;   CompuServe..:  73765,302                           :
  6. ;   Date........:  06/22/86                            :
  7. ;   Purpose.....:  Fill RAM with zeros from the lowest :
  8. ;                  user segment to the top of memory.  :
  9. ;   Note........:  Convert to .COM file.               :
  10. ;------------------------------------------------------:
  11.  
  12. CODE        SEGMENT PARA
  13.             ASSUME  CS:CODE,DS:CODE
  14.             ORG     100H              ;.COM file format
  15.  
  16. ;     the amount of installed memory is stored at offset 02H
  17. START:      MOV     DX,CS             ;reference lowest user seg
  18.             MOV     BX,02H            ;get top of memory from
  19.             MOV     AX,[BX]           ;   PSP and place in BX
  20.             MOV     BX,AX             ;   for segment counter
  21.             XOR     AX,AX             ;zero used for fill
  22.             CLD                       ;forward direction
  23.  
  24. ;     all but the last segment is cleared with this loop
  25. CLEAR_LOOP: SUB     BX,1000H          ;next lower 64k seg
  26.             CMP     BX,DX             ;lower than lowest?
  27.             JBE     LAST_SEG
  28.  
  29.             MOV     ES,BX             ;load seg reg
  30.  
  31.             XOR     DI,DI             ;initial offset
  32.             MOV     CX,8000H          ;word count for 64k
  33.  
  34.             REP     STOSW             ;fill with zeros
  35.  
  36.             JMP     CLEAR_LOOP        ;next segment
  37.  
  38. ;     the last segment contains fewer than 64 kilobytes
  39. LAST_SEG:   PUSH    CS                ;set ES to local seg
  40.             POP     ES
  41.  
  42.             LEA     DI,RAM_START      ;first byte after program
  43.  
  44.             AND     DX,0FFFH          ;clear high nibble
  45.             MOV     CL,4              ;shift count
  46.             SHL     DX,CL             ;convert to offset value
  47.  
  48. ;     DX now contains the offset from the next lower 64k boundary
  49.             ADD     DX,DI             ;plus offset of end of program
  50.  
  51.             XOR     CX,CX             ;set CX = # of bytes above
  52.             SUB     CX,DX             ;   prog not yet cleared
  53.  
  54.             REP     STOSB             ;fill what's left to clear
  55.  
  56.             INT     20H               ;terminate program
  57.  
  58. RAM_START   LABEL   BYTE              ;first byte after program
  59. CODE        ENDS                      ;end of segment
  60.             END     START             ;indicate program entry point
  61.