Near the end of tutorial 2, ADDR and OFFSET are discussed.  I understand ADDR is able to retrieve an address for a local/global variable as long as the label is defined prior to it's use.  I understand OFFSET is able to retrieve only global variables and can forwad reference.  Does this mean that it's good/normal practice to use ADDR all of the time? 

Does ADDR use more CPU cycles than OFFSET since ADDR expands to two more instructions?

LEA EAX, localVar

Posted on 2006-04-11 15:06:02 by jr_dwj
OFFSET is calculated at compile time. Generally you want to use OFFSET for variables that are globally defined and the address never changes. ADDR can be used on local variables (unlike OFFSET) because it calculates the address during execution.
Posted on 2006-04-11 15:09:56 by Synfire
Local variables are located in stack, because the stack use a regisrter and you dont know the value of such a register at assembly/compile time, then you dont know wich number (addres) is ebp+4 or ebp-4.

See the diference of a label (address) at your assembly in code or data (the address can be calculated from the start of the section that will be otuput to the object file),  in tat moment the assembler know where are "the things" or the numbers for such addresses.
Posted on 2006-04-11 16:06:27 by rea
Do a test:

make 2 variables: one global (var1), and 1 local (on the stack) (var2). then do

mov eax, variable1
mov ecx, variable2
mov edx, offset variable1
mov eax, addr variabl2

then see (using a debugger) how it looks like. Seeing something yourself is much better than reading about it. ;)
Posted on 2006-04-11 18:49:02 by ti_mo_n