Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASM - What is "%" used for?

Tags:

x86

assembly

att

What is the use of "%" in assembly? For example, sometimes an instruction is written as:

movl %eax, %ebx

and other times it's written as:

movl eax, ebx

(without the percent symbol) what is the difference?

like image 236
user1203441 Avatar asked Sep 12 '25 05:09

user1203441


1 Answers

For all assemblers, there's a problem when you need to refer to a symbol that happens to have the same name as a register. For example, if you've got some C code that has the function "int eax()" in it and you link it with some assembly code that does "mov ebx,eax", then the assembler needs to know if "eax" is the register or if it's the function.

To get around that different assemblers do different things. Some (e.g. NASM) would assume "eax" is the register and would require some sort of prefix for ambiguous symbols (e.g. "$eax" to refer to the symbol rather than the register). Others (e.g. GAS) do the opposite and add a prefix to the register name; sometimes even if there's no ambiguity at all (e.g. "%eax" to refer to the register and "eax" to refer to the symbol).

like image 198
Brendan Avatar answered Sep 14 '25 22:09

Brendan