Hello,
Learning ASM seem to me a VAST TASK,
I still have yet only a HALF-VAST idea of what I do ;)

So I try to code a proc to return first space delimited word
from memorymappedfile. ... If I can do one then can do all...
But, it's not working, like I think I have it correct but not.

Anyway, if you can read this ugly post my questions are in
comments below...

TIA Guys

.data?
Tmp DWORD ?
pTmp DWORD ?
pMemory DWORD ?
hFileRead HANDLE ?
InputFileSize DWORD ?

.code

start:

call main
invoke ExitProcess,0

Find_Word proc uses edi esi lpszFile:DWORD,lpszDest:DWORD
;----------------------------------------------------------------------
; Copy first 'Space' delimited word in memorymappedfile to destination and return
;----------------------------------------------------------------------
mov esi, lpszFile ; put memory mapped file address into the source index
mov edi, lpszDest ; put destination address into the destination index
@@:
mov al, ; copy byte at address in esi to al
cmp al, 32 ; look for ascii space
je @F ; done so return
inc esi ; increment address in esi
mov , al ; copy byte in al to address in edi
inc edi ; increment address in edi
jmp @B ; keep looking
@@:
ret
Find_Word endp

main proc
LOCAL clBuffer[128]:BYTE
invoke GetCL,1, ADDR clBuffer
.if eax == 1 ; return value 1 is GetCL successful
invoke CreateFile,ADDR clBuffer,\
GENERIC_READ ,\
0,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFileRead,eax
invoke CreateFileMapping,hFileRead,NULL,PAGE_READONLY,0,0,NULL
mov hMapFile,eax
invoke MapViewOfFile,hMapFile,FILE_MAP_READ,0,0,0
mov pMemory,eax
invoke GetFileSize,hFileRead,NULL
mov InputFileSize, eax
.if InputFileSize == 0FFFFFFFFh
invoke MessageBox,0,SADD("Failed GetFileSize"),SADD("Failed"),MB_OK
.endif

;???????????????????????????????????????????????????????????????????????????????
;invoke Find_Word, pMemory,ADDR Tmp ; Q1. Would'nt 'ADDR Tmp' and 'pTmp' below be same thing?
;???????????????????????????????????????????????????????????????????????????????

lea eax, Tmp
mov pTmp, eax
invoke Find_Word, pMemory,pTmp

;???????????????????????????????????????????????????????????????????????????????
PrintStringByAddr pTmp ; Q2. Why does this not print first word in file,only prints 'pTmp ='?
PrintStringByAddr pMemory ; But this prints the entire file contents ok.
;???????????????????????????????????????????????????????????????????????????????

.elseif eax == 2
invoke MessageBox,0,SADD("GetCl returned 2"),SADD("Failure"),MB_OK
.elseif eax == 3
invoke MessageBox,0,SADD("GetCl returned 3"),SADD("Failure"),MB_OK
.elseif eax == 4
invoke MessageBox,0,SADD("GetCl returned 4"),SADD("Failure"),MB_OK
.endif

call CloseMapFile
invoke UnmapViewOfFile,pMemory

ret

main endp

end start
Posted on 2002-04-29 00:39:21 by retinitis
Afternoon, retinitis.

ummm.....what? It seems to be working fine. The only problem I see is that you've got to make sure that any strings have a zero on the end.

Cheers,
Scronty
Posted on 2002-04-29 01:48:25 by Scronty