Category : Pascal Source Code
Archive   : FINDMEM.ZIP
Filename : FINDMEM.ASM

 
Output of file : FINDMEM.ASM contained in archive : FINDMEM.ZIP
;*****************************************************************************
;
;Written 11-5-88 by Jeff Mock user id 74106,1031
;Leave me a message if you can think of any enhancements to this code
;
; Function FindMem(Segment,Offset,Count:word;
; Search:string;
; var Location:dword) : boolean;
;
;Purpose: Search for a byte or string of bytes in any memory segment
;
;Assembled with borland turbo assembler 1.0
;
;Example for use with borland turbo pascal 5.0
;
;Program test;
;
;var Location:word;
; t:boolean;
;
;{$F+}
;function FindMem(Seg_Ment,Off_set,Count:word;s:string;var Location:word) : boolean; external;
;{$L findmem.obj}
;{$f-}
;
;begin
; t:=FindMem(0,0,$ffff,'NUL',Location);
; if t then writeln('String "NUL" found at segment 0 offset decimal ',Location);
;end.
;
;This can be rewritten as a near function depending on where you are going
;to place it in your program
;
;*****************************************************************************

.model TPASCAL
.CODE
FindMem PROC FAR Seg_ment:WORD,Off_set:WORD,Count:WORD,String:DWORD,Location:DWORD
PUBLIC FindMem
mov es,Seg_ment ;Get search segment
mov dx,Off_set ;Get starting offset in segment
mov cx,Count ;Get search count
mov bx,ds ;Save data segment
cont:
lds si,string ;Get segment/offset to search string
inc si ;Increment past string length byte
mov di,dx ;set offset address
mov al,[si] ;Get first search string character
cld ;Set direction flag to foward
repnz scasb ;Search for byte
jcxz nomatch ;Jump if not found
mov dx,di ;Else save current segment offset
dec di ;Point offset back to found byte
xor ax,ax ;Zero ax
push ds ;Save segment/offset temp.
push si
lds si,string ;Point back to string start
mov al,[si] ;Get length byte
pop si ;Restore segment/offset
pop ds
inc ax ;Increment length count
xchg cx,ax ;Exchange count values
rep cmpsb ;Compare bytes from string and memory
jcxz found ;Jump if bytes match
xchg cx,ax ;Else restore segment count to cx
jmp cont ;Continue search untill string found or count=0
nomatch:
mov al,0 ;Set function boolean to false/string not found
jmp exit ;Exit function
found:
dec dx ;Set up string offset location/string found
lds si,Location ;Get varible storage location
mov [si],dx ;Save found string offset location in varible
mov al,1 ;Set function to true/string found
exit:
mov ds,bx ;Restore programs data segment
ret ;Return to caller
FindMem ENDP

CODE ENDS

END



  3 Responses to “Category : Pascal Source Code
Archive   : FINDMEM.ZIP
Filename : FINDMEM.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/