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?
e.g.
LEA EAX, localVar
PUSH EAX
Thanks.
Does ADDR use more CPU cycles than OFFSET since ADDR expands to two more instructions?
e.g.
LEA EAX, localVar
PUSH EAX
Thanks.
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.
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.
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.
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. ;)
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. ;)