Just got into asm a week or 2 ago, straight from Visual Basic, so all this memory stuff is still kinda hazy. I need a little clarification on what the relationship between addresses and offsets are, in my mind, an offset would be the location of a byte at a specified address, but somehow this doesnt seem the case, and im pretty sure that im going to need a much firmer grasp on address and offset handling/manipulation to get anywhere in asm. so any kind of feedback would be apreciated.
thx,
kenji
footnote: feel free to confuse me with example code :grin:
thx,
kenji
footnote: feel free to confuse me with example code :grin:
If you're talking about MASM's ADDR and OFFSET directives, then the difference is clear: ADDR is a macro (used with invoke) which automatically decides whether to use a direct offset or lea instruction for local variables (like ), since you can't do push OFFSET . OFFSET is a directive which puts in the address of a GLOBAL symbol as an immediate value, and such so it will not work on local variables.
ok, so in a sense, an offset is an address, and the ADDR macro simply recognizes wether the variable specified is local or global and handles it accordingly.
mk got it.
but then, whats the difference, i mean, i know the difference between global and local variables, but are they stored in different places? locals in the stack or what? im going through the motions, but id rather not just.
thx
kenji
mk got it.
but then, whats the difference, i mean, i know the difference between global and local variables, but are they stored in different places? locals in the stack or what? im going through the motions, but id rather not just.
thx
kenji
locals are stored on the stack and have to be accessed using .
Globals are stored in the data section of your program and can be accesed using a file offset.
Globals are stored in the data section of your program and can be accesed using a file offset.
For global variables, MASM already knows where they are and can insert a direct address. Local variables are relative to the stack, and stack offset is different at run-time, so MASM has no way of knowing its position during assembly time. Therefore, it uses lea instruction to reference local variables and places direct offsets for global variables.
surprisingly i understood every word of that.
thx a bunch guys
thx a bunch guys