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?
$ is used to refer to the current address and $$ is used to refer to the address of the start of current section 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.
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'
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.
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.
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()
is used for memory reference, like []
in Intel syntaxSo 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`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With