home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / EXAMPLES / MEMTEST.ZIP / MEMTEST.ASM next >
Encoding:
Assembly Source File  |  1995-06-07  |  4.9 KB  |  255 lines

  1. comment $
  2. ***************************************************************************
  3.  MEMTEST.ASM
  4.  
  5.  This program will allocate memory any fill it with zeros. It then
  6.  checks to see if any of the inital programs code/data is overwritten.
  7.  
  8.  This coded is written extreamily badly. 
  9.  
  10. ***************************************************************************$
  11. .386p
  12.  
  13. .MODEL FLAT
  14. .STACK 100h
  15.  
  16.  
  17. .data
  18.  
  19. Block               db 0
  20. Align 4
  21. My_array2           db 10000 dup ('HELP')
  22. LargestMemoryBlock  dd ?
  23. dma_addr            dd ?
  24. MemPtr              dd 10 dup (?)
  25. .CODE
  26.  
  27.  
  28.  
  29. My_array3       db 10000 dup ('WASH')
  30.  
  31.  
  32. ;  Macro to print some text on the screem
  33. ;
  34. Print MACRO string
  35. local @text,@skip
  36.     mov edx,offset @text
  37.     mov ah,9
  38.     int 21h
  39.     jmp @skip
  40. @text db string,36
  41. @skip:
  42. ENDM
  43.  
  44. IS_OK_or_BAD MACRO
  45. local bad , good
  46.       jc bad
  47.        Print <'.  (Successful)',13,10>
  48.       jmp good
  49. bad:
  50.        Print <'.  ( ERROR !)',13,10>
  51. good:
  52. ENDM
  53.  
  54. _IF MACRO reg,val,mesg
  55. local JJ
  56.       cmp   reg,val
  57.       jne JJ
  58.       Print <mesg>
  59. JJ:
  60. ENDM
  61.  
  62. start:                                         ; Start of program
  63.  
  64.     Print 'System type: '
  65.     mov    ax,0EE00h
  66.     int    31h
  67.     _IF DL,1 ,<'Raw ',13,10>
  68.     _IF DL,2 ,<'XMS',13,10>
  69.     _IF DL,4 ,<'VCPI',13,10>
  70.     _IF DL,8 ,<'DPMI',13,10>
  71.  
  72.     Print ' Allocating a 16KB DMA buffer and filling'
  73.     mov  ax,0ee41h
  74.     int  31h
  75.     mov   dma_addr,edx
  76.     IS_OK_or_BAD
  77.     mov     ecx,16*1024/4          ; fill the allocated block with zeros
  78.     mov     edi,dma_addr
  79.     mov     eax,12345678h
  80.     cld
  81.     rep     stosd
  82.  
  83.  
  84.     Print ' Attempting to allocate 4Gb'
  85.     mov  ax,0ee42h
  86.     mov  edx,-1
  87.     int  31h
  88.     test eax,eax
  89.     jz  Error
  90.  
  91.     Print <'. (Successful)',13,10>
  92.  
  93.     mov  LargestMemoryBlock,eax        ; Save maximum memory avalible
  94.  
  95.     Print ' Deallocating the block'
  96.     mov   ax,0ee40h
  97.     int  31h
  98.     IS_OK_or_BAD
  99.  
  100.  
  101.  
  102.     ;
  103.     ; Allocate one quarter of the maximum avalible memory four times.
  104.     ;
  105.  
  106. REPT 3
  107. local @@KKK
  108.     Print ' Allocating a memory block and filling'
  109.     mov    edx,LargestMemoryBlock    ; Allocate 1/4 of avalible memory
  110.     shr    edx,4
  111.     mov    ax,0ee42h
  112.     int    31h
  113.     pushfd
  114.     pushad
  115.     IS_OK_or_BAD
  116.     popad
  117.     popfd
  118.     jc @@KKK
  119.     mov     ecx,eax                  ; fill the allocated block with zeros
  120.     mov     edi,edx
  121.     movzx   eax,Block
  122.     mov     MemPtr[eax*4],edi         ; save pointer
  123.     add     al,12h
  124.     mov     ah,al
  125.     push    ax
  126.     push    ax
  127.     pop     eax
  128.     cld
  129.     rep     stosb
  130.     inc     Block
  131. @@KKK:
  132. ENDM
  133.  
  134.  
  135.  
  136. REPT 3
  137. local @@JJ,Error,Good
  138.     Print <' checking memory block '>
  139.     dec     Block
  140.     movzx   ebx,Block
  141.     mov     edi,MemPtr[ebx*4]
  142.     mov     al,bl
  143.     add     al,12h
  144.     mov     ah,al
  145.     push    ax
  146.     push    ax
  147.     pop     eax
  148.     mov     ecx,LargestMemoryBlock
  149.     shr     ecx,6
  150.     cld
  151.     repe    scasd
  152.     jne Error
  153.        Print <'.  (Successful)',13,10>
  154.     jmp Good
  155. Error:
  156.        Print <'.  ( ERROR !)',13,10>
  157. Good:
  158.  
  159.  
  160. ENDM
  161.  
  162.     Print <' checking DMA buffer '>
  163.     mov     edi,dma_addr
  164.     mov     eax,12345678h
  165.     mov     ecx,16*1024/4
  166.     cld
  167.     repe    scasd
  168.     jne Errordma
  169.        Print <'.  (Successful)',13,10>
  170.     jmp Gooddma
  171. Errordma:
  172.        Print <'.  ( ERROR !)',13,10>
  173. Gooddma:
  174.  
  175.  
  176.  
  177. REPT 3
  178.     Print ' Deallocating memory block'
  179.     mov   ax,0ee40h
  180.     int  31h
  181.     IS_OK_or_BAD
  182. ENDM
  183.  
  184.     Print ' Deallocating DMA buffer'
  185.     mov   ax,0ee40h
  186.     int  31h
  187.     IS_OK_or_BAD
  188.  
  189.  
  190.  
  191.     ;
  192.     ; checking arrays to make sure they did not get trashed while filling the
  193.     ; allocated memory blocks.
  194.     ;
  195.     Print <' Checking data arrays to make sure they were not written over',13,10>
  196.  
  197.     Print  '   1st array'
  198.     xor   edi,edi
  199. @@LL01:
  200.     cmp   dword ptr My_array1[edi*4],'EKIL'
  201.     jne Error01
  202.     inc   edi
  203.     cmp   edi,10000
  204.     jb @@LL01
  205.        Print <'.  (Successful)',13,10>
  206.     jmp Good01
  207. Error01:
  208.        Print <'.  ( ERROR !)',13,10>
  209. Good01:
  210. ;--------------------------------------------------
  211.     Print  '   2nd array'
  212.     xor   edi,edi
  213. @@LL02:
  214.     cmp   dword ptr My_array2[edi*4],'PLEH'
  215.     jne Error02
  216.     inc   edi
  217.     cmp   edi,10000
  218.     jb @@LL02
  219.        Print <'.  (Successful)',13,10>
  220.     jmp Good02
  221. Error02:
  222.        Print <'.  ( ERROR !)',13,10>
  223. Good02:
  224. ;--------------------------------------------------
  225.     Print  '   3rd array'
  226.     xor   edi,edi
  227. @@LL03:
  228.     cmp   dword ptr My_array3[edi*4],'HSAW'
  229.     jne Error03
  230.     inc   edi
  231.     cmp   edi,10000
  232.     jb @@LL03
  233.        Print <'.  (Successful)',13,10>
  234.     jmp Good03
  235. Error03:
  236.        Print <'.  ( ERROR !)',13,10>
  237. Good03:
  238.  
  239.  
  240.      Print <'Memory test complete',13,10>
  241. exit:
  242.     mov ax,4c00h
  243.     int 21h
  244.  
  245.  
  246.  
  247. Error:
  248.  Print <"Error and exiting..." ,13,10>
  249.  jmp exit
  250.  
  251.  
  252. My_array1       db 10000 dup ('LIKE')
  253.  
  254. END  Start
  255.