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:
Posted on 2002-06-28 14:49:55 by kenji
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.
Posted on 2002-06-28 15:12:01 by comrade
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
Posted on 2002-06-28 15:37:02 by 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.
Posted on 2002-06-28 15:57:43 by Kudos
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.
Posted on 2002-06-28 16:11:42 by comrade
surprisingly i understood every word of that.

thx a bunch guys
Posted on 2002-06-28 16:18:31 by kenji