home *** CD-ROM | disk | FTP | other *** search
- comment $
- ***************************************************************************
- MEMTEST.ASM
-
- This program will allocate memory any fill it with zeros. It then
- checks to see if any of the inital programs code/data is overwritten.
-
- This coded is written extreamily badly.
-
- ***************************************************************************$
- .386p
-
- .MODEL FLAT
- .STACK 100h
-
-
- .data
-
- Block db 0
- Align 4
- My_array2 db 10000 dup ('HELP')
- LargestMemoryBlock dd ?
- dma_addr dd ?
- MemPtr dd 10 dup (?)
- .CODE
-
-
-
- My_array3 db 10000 dup ('WASH')
-
-
- ; Macro to print some text on the screem
- ;
- Print MACRO string
- local @text,@skip
- mov edx,offset @text
- mov ah,9
- int 21h
- jmp @skip
- @text db string,36
- @skip:
- ENDM
-
- IS_OK_or_BAD MACRO
- local bad , good
- jc bad
- Print <'. (Successful)',13,10>
- jmp good
- bad:
- Print <'. ( ERROR !)',13,10>
- good:
- ENDM
-
- _IF MACRO reg,val,mesg
- local JJ
- cmp reg,val
- jne JJ
- Print <mesg>
- JJ:
- ENDM
-
- start: ; Start of program
-
- Print 'System type: '
- mov ax,0EE00h
- int 31h
- _IF DL,1 ,<'Raw ',13,10>
- _IF DL,2 ,<'XMS',13,10>
- _IF DL,4 ,<'VCPI',13,10>
- _IF DL,8 ,<'DPMI',13,10>
-
- Print ' Allocating a 16KB DMA buffer and filling'
- mov ax,0ee41h
- int 31h
- mov dma_addr,edx
- IS_OK_or_BAD
- mov ecx,16*1024/4 ; fill the allocated block with zeros
- mov edi,dma_addr
- mov eax,12345678h
- cld
- rep stosd
-
-
- Print ' Attempting to allocate 4Gb'
- mov ax,0ee42h
- mov edx,-1
- int 31h
- test eax,eax
- jz Error
-
- Print <'. (Successful)',13,10>
-
- mov LargestMemoryBlock,eax ; Save maximum memory avalible
-
- Print ' Deallocating the block'
- mov ax,0ee40h
- int 31h
- IS_OK_or_BAD
-
-
-
- ;
- ; Allocate one quarter of the maximum avalible memory four times.
- ;
-
- REPT 3
- local @@KKK
- Print ' Allocating a memory block and filling'
- mov edx,LargestMemoryBlock ; Allocate 1/4 of avalible memory
- shr edx,4
- mov ax,0ee42h
- int 31h
- pushfd
- pushad
- IS_OK_or_BAD
- popad
- popfd
- jc @@KKK
- mov ecx,eax ; fill the allocated block with zeros
- mov edi,edx
- movzx eax,Block
- mov MemPtr[eax*4],edi ; save pointer
- add al,12h
- mov ah,al
- push ax
- push ax
- pop eax
- cld
- rep stosb
- inc Block
- @@KKK:
- ENDM
-
-
-
- REPT 3
- local @@JJ,Error,Good
- Print <' checking memory block '>
- dec Block
- movzx ebx,Block
- mov edi,MemPtr[ebx*4]
- mov al,bl
- add al,12h
- mov ah,al
- push ax
- push ax
- pop eax
- mov ecx,LargestMemoryBlock
- shr ecx,6
- cld
- repe scasd
- jne Error
- Print <'. (Successful)',13,10>
- jmp Good
- Error:
- Print <'. ( ERROR !)',13,10>
- Good:
-
-
- ENDM
-
- Print <' checking DMA buffer '>
- mov edi,dma_addr
- mov eax,12345678h
- mov ecx,16*1024/4
- cld
- repe scasd
- jne Errordma
- Print <'. (Successful)',13,10>
- jmp Gooddma
- Errordma:
- Print <'. ( ERROR !)',13,10>
- Gooddma:
-
-
-
- REPT 3
- Print ' Deallocating memory block'
- mov ax,0ee40h
- int 31h
- IS_OK_or_BAD
- ENDM
-
- Print ' Deallocating DMA buffer'
- mov ax,0ee40h
- int 31h
- IS_OK_or_BAD
-
-
-
- ;
- ; checking arrays to make sure they did not get trashed while filling the
- ; allocated memory blocks.
- ;
- Print <' Checking data arrays to make sure they were not written over',13,10>
-
- Print ' 1st array'
- xor edi,edi
- @@LL01:
- cmp dword ptr My_array1[edi*4],'EKIL'
- jne Error01
- inc edi
- cmp edi,10000
- jb @@LL01
- Print <'. (Successful)',13,10>
- jmp Good01
- Error01:
- Print <'. ( ERROR !)',13,10>
- Good01:
- ;--------------------------------------------------
- Print ' 2nd array'
- xor edi,edi
- @@LL02:
- cmp dword ptr My_array2[edi*4],'PLEH'
- jne Error02
- inc edi
- cmp edi,10000
- jb @@LL02
- Print <'. (Successful)',13,10>
- jmp Good02
- Error02:
- Print <'. ( ERROR !)',13,10>
- Good02:
- ;--------------------------------------------------
- Print ' 3rd array'
- xor edi,edi
- @@LL03:
- cmp dword ptr My_array3[edi*4],'HSAW'
- jne Error03
- inc edi
- cmp edi,10000
- jb @@LL03
- Print <'. (Successful)',13,10>
- jmp Good03
- Error03:
- Print <'. ( ERROR !)',13,10>
- Good03:
-
-
- Print <'Memory test complete',13,10>
- exit:
- mov ax,4c00h
- int 21h
-
-
-
- Error:
- Print <"Error and exiting..." ,13,10>
- jmp exit
-
-
- My_array1 db 10000 dup ('LIKE')
-
- END Start