home *** CD-ROM | disk | FTP | other *** search
- INCLUDE MACROS.ASM
-
- CODE SEGMENT BYTE PUBLIC
- ASSUME CS:CODE
-
- PUBLIC SearchBlock
-
- ;SearchBlock(var FindStr; FindSize : Word; var Block;
- ; BlockSize : Word) : Word;
-
- FindStr EQU DWORD PTR [BP+0Eh]
- FindSize EQU WORD PTR [BP+0Ch]
- Block EQU DWORD PTR [BP+08h]
- BlockSize EQU WORD PTR [BP+06h]
-
- SearchBlock PROC FAR
- PUSH BP
- MOV BP,SP ; stack frame with BP
- PUSH DS
- XOR AX,AX
- MOV CX,BlockSize
- JCXZ ExitCode ; if BlockSize = 0 then all done
- MOV BX,CX
-
- MOV DX,FindSize
- OR DX,DX
- JZ ExitCode ; if FindSize = 0 then all done
-
- CMP DX,BX
- JA ExitCode ; FindStr is bigger than Block
-
- SUB CX,DX ; adjust CX for size of FindStr
- INC CX
-
- CLD ; forward string ops
-
- LES DI,Block ; the block to search is dest
- _Normal_ ES,DI
-
- FindFirstChar:
- LDS SI,FindStr ; the string to find is source
-
- LODSB ; load first byte into AL
- REPNE SCASB ; look for match of first byte
- JNZ NotFound ; if Z flag not set then exit
-
- MOV AX,CX ; save CX in AX
- MOV CX,DX ; get FindSize
-
- PUSH DI ; push posit in block in case
- ; we need to restart search
-
- DEC CX ; we already found first char
- JCXZ Bingo ; if FindSize was 1 then we
- ; found it!
-
- FindRest:
- REPE CMPSB ; cmp source to dest while =
- JZ Bingo ; if Z is set then we found it
-
- POP DI ; restore index into dest
- MOV CX,AX ; restore loop counter
- JCXZ NotFound ; no more block to search
- INC CX
- LOOP FindFirstChar ; re-start the search
-
- NotFound:
- XOR AX,AX ; if we make it here then the
- JMP SHORT ExitCode ; jump to exit code
-
- Bingo:
- POP DI ; we must pop DI off the stack
-
- SUB BX,DX ; account for FindSize
- INC BX
- SUB BX,AX ; calculate posit
-
- MOV AX,BX ; store as function result
-
- ExitCode:
- POP DS
- POP BP
- RET 0Ch
- SearchBlock ENDP
-
- CODE ENDS
-
- END