Hi! I was playing with the codes, than I noticed that I am confused about strings(see my previous posts on old forum. I keep making mistakes on strings :biggrin:).
source db "uosunsetter",0 ; null terminated string
When I use "source", what I think is I'm using the address of first char in the string. With other words, "source" represents the beginning of the buffer as a reference, byte pointer. For example:
mov esi, source
Now esi has the address of letter "u" right? To access the next letter I just increase esi and move [esi] to ah. However here I get confused:
push MB_OKCANCEL
push offset source
push offset source
push 0
call MessageBox
What is this??? What am I pushing? Pointer of pointer? Why not only "source"? This example was the first example I saw, thus, I was using strings in this way which is not true I guess:
mov esi, OFFSET source
I don't even know what it does now. :(
mov esi,source ; load a value in esi (4 bytes ,the size of esi) from the adress of source
lea esi, source ; load the adresse of source in esi:The linker could change this one
mov esi,offset source
;same as lea except that it is the compiler who give the adress replacing offset source by a constant (the linker couldn't change this)
with functions:
invoke MessageBox,NULL,ADDR source,addr Titre,MB_OK
source db "uosunsetter",0
mov esi, source
ESI will hold 'usou', the first 4 bytes in little-endian order
what you want is...
mov esi, offset source
now, ESI holds the address of source
soure is not a byte pointer. there isn't byte pointer in masm32. all the pointers is dword.
Quote from: tuohai on August 23, 2012, 02:13:32 AM
soure is not a byte pointer. there isn't byte pointer in masm32. all the pointers is dword.
include \masm32\include\masm32rt.inc
.code
source db "uosunsetter",0 ; null terminated string
start:
mov esi, offset byte ptr source
MsgBox 0, esi, 0, MB_OK
exit
end start
;)
... and welcome to the forum :icon14:
Hi tuohai,
There are also qword pointers.
Erol, the assembler zoo is full of strange animals :P
While we're on it:
mov esi,source
this won't assemble, because source is of the type BYTE whereas ESI is DWORD :badgrin:
It should be mention that MASM automatically dereference data labels (unlike other assmblers)– to get the Pointer requires the OFFSET/ADDR operator or a instruction like LEA.
Thanks for making it clear. I really need to learn proper debugging to avoid that kind of noob questions :)
Just to clarify something in a previous post.
> soure is not a byte pointer. there isn't byte pointer in masm32. all the pointers is dword.
There IS in fact such a thing as a BYTE PTR in 32 bit MASM, it is a DWORD that points to a BYTE location, usually the start of a string sequence of bytes. In 16 bit DOS it was a BYTE PTR that was a WORD and if we ever get a fully long 64 bit mode, a BYTE PTR will be a 64 bit unsigned integer.
To the original question, its a distinction between WHERE data is located (its address) and WHAT the data is (its content).