Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the dollar ($) and percentage (%) signs represent in x86 assembly?

Tags:

x86

assembly

att

I am trying to understand how the assembly language works for a micro-computer architecture class, and I keep facing different syntaxes in examples:

sub $48, %esp mov %eax, 32(%esp) 

What do these codes mean? What is the 32 operand an addition to the esp register?

like image 963
juliensaad Avatar asked Feb 08 '12 15:02

juliensaad


People also ask

What does $$ mean in x86 assembly?

$ is used to refer to the current address and $$ is used to refer to the address of the start of current section in assembly.

What does $$ mean in assembly?

In assemblers, symbol $ usually means two different things: Prefixing a number, means that this number is written in hexadecimal. By itself, $ is a numeric expression that evaluates as "the current position", that is, the address where the next instruction/data would be assembled.

What do brackets mean in x86?

Square brackets means 'the variable at the memory address stored in RAX”. So: mov RAX, 12. means “store value 12 into RAX” mov [RAX], 12. means “store value 12 in the memory cell whose address is stored in RAX'

What does and mean in assembly?

The AND operation can be used for clearing one or more bits. For example, say the BL register contains 0011 1010. If you need to clear the high-order bits to zero, you AND it with 0FH.


2 Answers

Thats not Intel syntax, its AT&T syntax, also called GAS syntax.

the $ prefix is for immediates (constants), and the % prefix is for registers (they are required1).

For more about AT&T syntax, see also the [att] tag wiki.


1 Unless the noprefix option is specified, see here & here. But usually noprefix is only used with .intel_syntax noprefix, to get MASM-like syntax.

like image 148
Necrolis Avatar answered Sep 19 '22 14:09

Necrolis


Compared to Intel syntax, AT&T syntax has many differences

  • $ signifies a constant (integer literal). Without it the number is an absolute address
  • % denotes a register
  • The source/destination order is reversed
  • () is used for memory reference, like [] in Intel syntax

So the above snippet is equivalent to

sub esp, 48         ; esp -= 48 mov [esp+32], eax   ; store eax to the value at the address `esp + 32` 
like image 23
phuclv Avatar answered Sep 18 '22 14:09

phuclv