home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / tsrsrc.zip / EATMEM.ASM < prev    next >
Assembly Source File  |  1991-10-07  |  3KB  |  100 lines

  1. ;use up memory by allocating and staying resident
  2. ;for memory size testing of various programs
  3. ;call as EATMEM kBytesToEat
  4. ;
  5. ;written 8/7/85 Kim Kokkonen, TurboPower Software
  6. ;modified 5/2/87 to use MASM version 4.0
  7.  
  8. Cseg    segment public para
  9.         assume  cs:Cseg, ds:Cseg, es:Cseg
  10.         org     100H
  11.  
  12. eat     proc    near
  13.  
  14. ;parse command line to get amount of memory to eat
  15. comentry:
  16.         mov     si,0081H           ;point to command line string
  17.         mov     di,offset amount$  ;and to string storage area
  18.         xor     cx,cx              ;count chars in cx
  19.         cld
  20. getst:  lodsb                      ;get first non-blank
  21.         cmp     al,' '
  22.         je      getst
  23.         cmp     al,13              ;check for end of input
  24.         jne     more
  25.         mov     dx,offset noinp$   ;no parameter specified ==>error
  26.         jmp     short error
  27.  
  28. more:   inc     cx
  29.         stosb                      ;store the non-blank character
  30.         lodsb                      ;get next char into al
  31.         cmp     al,' '             ;terminate with <space> or <cr>
  32.         je      done
  33.         cmp     al,13
  34.         je      done
  35.         jmp     short more
  36.  
  37. ;convert amount$ to an integer in amount
  38. ;cx holds count of chars
  39. done:   mov     al,36
  40.         stosb                      ;put string terminator on amount$
  41.         mov     si,offset amount$
  42.         mov     di,10
  43.         inc     cx
  44. nextc:  dec     cx
  45.         jcxz    eatit              ;exit if all digits used
  46.  
  47.         mov     ax,amount          ;partial result into ax
  48.         mul     di                 ;multiply by 10 (should all fit in ax)
  49.         mov     amount,ax          ;store ax
  50.  
  51.         lodsb                      ;next char into al
  52.         cmp     al,30H             ;make sure it's a digit
  53.         jb      baddig
  54.         cmp     al,39H
  55.         ja      baddig
  56.         and     al,0FH             ;convert to digit
  57.         xor     ah,ah
  58.         add     amount,ax          ;add to amount
  59.         jmp     short nextc
  60.  
  61. ;calculate the paragraphs to eat up
  62. eatit:  mov     dx,amount
  63.         cmp     dx,512
  64.         ja      baddig             ;don't eat more than 512k
  65.         push    dx
  66.  
  67. ;show a success message
  68.         mov     dx,offset succ1$
  69.         mov     ah,9
  70.         int     21H
  71.         mov     dx,offset succ2$
  72.         mov     ah,9
  73.         int     21H
  74.  
  75. ;eat up the memory (free with mark and release)
  76.         pop     dx
  77.         mov     cl,6
  78.         shl     dx,cl           ;convert kB to paras
  79.         mov     ax,3100H        ;return code 0
  80.         int     21H             ;exit and remain resident
  81.  
  82. baddig: mov     dx,offset baddig$
  83.  
  84. error:  mov     ah,9
  85.         int     21H
  86.         mov     ax,4C01H
  87.         int     21H
  88.  
  89. eat     endp
  90.  
  91. succ1$  db      'Eating up '
  92. amount$ db      32,32,32,32                 ;string holding amount of kB
  93. succ2$  db      ' kBytes of RAM space',13,10,36
  94. amount  dw      0                           ;integer holding amount of kb, then paras
  95. noinp$  db      'No parameter specified. Usage: EATMEM kBtoEat',13,10,36
  96. baddig$ db      'Bad number of kB specified',13,10,36
  97.  
  98. Cseg    ends
  99.         end     ComEntry
  100.