If I use esi, edi, and ebx in a proc instead of a variable (LOCAL or data?) do I have to zero it before I use it next time? example:

; open treeview data file for read
push 0 ;
push 0 ;
push 0 ;
push DataFile ;
call CreateFile ;
mov esi, eax ; save file handle

push 0 ; Get file size for buffer
push esi ; file handle
call GetFileSize ;
mov ebx, eax ; save file size

push esi ; file handle to close
call CloseHandle ;

; Allocate a buffer to read file into
push ebx ; file size
push hHeap ;
call HeapAlloc ;
mov hTempBuf, eax ; save memory block pointer

; Get all sections and load into memory
invoke GetPrivateProfileSectionNames, addr hTempBuf, ebx, addr DataConfiglPath

lea esi, hTempBuf ; do I have to xor esi before I do this?????

as I am still learning and many docs don't cover what questions I have, this board is invaluable to me! Since I used esi as the file handle, do I have to/ should I zero esi before I lea hTempBuf into it? As of now, I am not and all seems to work on Win98 and 2K but if it is wrong, I would like to fix it....

Posted on 2003-01-09 17:56:49 by Gunner
"..do I have to/ should I zero esi before I lea hTempBuf into it? "

Posted on 2003-01-09 18:06:36 by lingo12
you should zero a container (for a return value) if its value has any significance and you need to be absolutely sure.

e.g. a call to a routine returns 00 when failed (but you're not sure the routine is implemented correctly by its programmer) then you zero out first before you call so that you'll always get at least zero in case of non-success. (else you might get whatever was in there to begin with)

here the lea will fill your register and lea is known to work (;) ) so it's not necessary to zero it first.
Posted on 2003-01-09 18:07:21 by Hiroshimator
Nope... you overwrite esi's value... No need to zero anything before you overwrite...

Posted on 2003-01-09 18:07:41 by JimmyClif
Drinking Tip #01: Stop drinking when you're laughing and bleeding at the same time.

JC, where are the rest of your drinking tips?

Ok, so I only zero a register for a return value if I want one? (and if I want zero as a return) otherwise, I don't have to zero a register cause I will overwrite what is in it?

Ok, that helps.

Posted on 2003-01-09 18:22:14 by Gunner
I thought I'd change them weekly... but then I kind of forgot... Let's see what I can come up with...
Posted on 2003-01-09 18:50:49 by JimmyClif
he passed out after the first tip :grin:
Posted on 2003-01-09 19:20:44 by Hiroshimator
lea doesn't even modify any flags so you can pretty much expect you don't have to zero the register.

as a matter of fact if you were to zero with... xor esi,esi

it would modify CF OF PF SF ZF (AF undefined)

lea is a beautifull instruction...nice and clean as long as the stack is clean also
Posted on 2003-01-09 23:29:41 by IwasTitan

he passed out after the first tip :grin:

From alcohol or loss of blood?:grin:

Or both?:eek:
Posted on 2003-01-10 02:01:58 by ThoughtCriminal