07-24-2023, 03:00 AM
I normally don't spend much time reading assembly, so the following compiler output confused me a little.
Say I compile this piece of C code on my Intel Core 2 Duo running OSX 10.6:
while (var != 69) // var is a global variable
{
printf("Looping!\n");
}
The assembly for the "var != 69" comparison looks like:
cmpl $69, _var(%rip)
I understand that it effectively means to compare the value "69" against the contents of the global variable "var", but I'm having a tough time understanding the "_var(%rip)" part. Normally, I expect there to be a offset value, like for referring to local variables in the stack (eg: -4($ebp)). However, I don't quite following how offsetting the instruction pointer with the "_var" declaration will give me the contents of the global variable "var".
What exactly does that line mean?
Thanks.
Say I compile this piece of C code on my Intel Core 2 Duo running OSX 10.6:
while (var != 69) // var is a global variable
{
printf("Looping!\n");
}
The assembly for the "var != 69" comparison looks like:
cmpl $69, _var(%rip)
I understand that it effectively means to compare the value "69" against the contents of the global variable "var", but I'm having a tough time understanding the "_var(%rip)" part. Normally, I expect there to be a offset value, like for referring to local variables in the stack (eg: -4($ebp)). However, I don't quite following how offsetting the instruction pointer with the "_var" declaration will give me the contents of the global variable "var".
What exactly does that line mean?
Thanks.