Question

I am not able to understand the concept of absolute addressing and relative addressing in assembly particularly in gcc inline assembly. I saw the following code in a tutorial :

asm volatile("         \ 
     cli;                 \ 
     mov %0, %%ecx;       \ 
     mov %1, %%esp;       \ 
     mov %2, %%ebp;       \ 
     mov %3, %%cr3;       \ 
     mov $0x12345, %%eax; \ 
     sti;                 \ 
     jmp *%%ecx           "
                : : "r"(eip), "r"(esp), "r"(ebp), "r"(current_directory->physicalAddr));

Here the last instruction jmp *%%ecx uses a *. I could not find a good description of what is the significance of the asterisk except that it is used for absolute addressing. I am getting the idea that absolute means actual physical address while relative means offset from the start of the program. However I am not clear about the relative addressing. I read about PC-relative addressing in assembly but i don't understand it completely and it is not clear to me whether relative and PC-relative are same.Please explain.

Was it helpful?

Solution

The asterisk means nothing. The instruction is invalid without an asterisk. It is an artifact from the AT&T syntax, basically a mnemonic for "load dereferenced value of ecx into instruction decoder" which is equivalent to "jump to ecx".

In Intel syntax, the very same instruction would be jmp ecx.

There is no instruction for offset jump with the offset distance in an register. The "PC" is called ip (instruction pointer) on x86, "relative" without any further context usually means "relative to ip".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top