Differences between at&t and Intel assembly

Source: Internet
Author: User

Original http://blog.csdn.net/bigloomy/article/details/6581754

At&t assembly and 8086 assembly language, although the two are very similar, but still cannot read at&t Assembly according to the 8086 syntax rules, so we still need to look at the syntax rules of at&t assembly, when reading the kernel code, some of the Code that deals with hardware is compiled by at&t assembly, so it is inevitable that at&t assembly will be encountered. Let's take a look at the syntax rules of at&t assembly.

I. Case sensitivity
Commands in Intel format use uppercase letters, while commands in at&t format Use lowercase letters.
Example:
 
Intel at&t
MoV eax, EBX movl % EBX, % eax
 
Ii. Assignment direction of operands
In intel syntax, the first represents the destination operand, the second represents the source operand, and the assignment direction is from right to left.
The first in at&t syntax is the source operand, and the second is the destination operand. The direction is from left to right, which is natural.
Example:
Intel at&t
MoV eax, EBX movl % EBX, % eax
 
3. prefix
In intel syntax, the prefix is not required for registers and immediate numbers; In at&t, the prefix "%" is required for registers; immediate number
You need to add the prefix "$ ".
Example:
Intel at&t
MoV eax, 1 movl $1, % eax
 
The at&t symbol constant is referenced directly without a prefix, for example, movl value, % EBX, and value is a constant.
The prefix $ in front of the value indicates the address of the referenced symbol. For example, movl $ value and % EBX place the value address in EBX.
 
Bus lock prefix "Lock": Bus Lock operation. The "Lock" prefix is widely used in Linux core code.
Are not in SMP code. When the bus is locked, other CPUs cannot access the memory units at the locked address.
The operation code of the remote jump instruction and sub-process call instruction uses the prefix "L", which is ljmp, lcall, and
The returned command is pseudo-LRET.
Example:
Intel at&t
Call far section: Offset lcall $ secion: $ offset
JMP far section: Offset ljmp $ secion: $ offset
RET far satck_adjust LRET $ stack_adjust
 

Iv. Indirect addressing syntax
Intel uses "[", "]", while at&t uses "(", ")". In addition
The syntax is also different. Intel is segreg: [base + Index * scale + disp], while Intel is
% Segreg: disp (base, index, sale). segreg, index, scale, and disp are optional.
The default value 1 is used when the scale is not explicitly specified by index. Scale and disp do not need to be prefixed with "&".
Intel at&t
Instr Foo, segreg: [base + Index * scale + disp] instr % segreg: disp (base, index, scale), foo
 
V. suffix
In at&t syntax, the last letter of the most command operation code represents the size of the operand, and "B" represents byte (
Byte); "W" indicates word (2 bytes); "L" indicates long (4 bytes ). Memory operations processed in intel
Such as byte PTR, word PTR, and dword ptr.
Example:
Intel at&t
MoV Al, BL movb % BL, % Al
MoV ax, BX movw % BX, % ax
MoV eax, dword ptr [EBX] movl (% EBX), % eax
 
In the at&t assembly instruction, the Extended Instruction of the operand has two suffixes: One specifying the length of the source operand and the other
Specifies the length of the target operand. At&t's symbolic extension command is "movs", and the zero extension command is "movz" (corresponding
The intel commands are "movsx" and "movzx "). Therefore, "movsbl % Al, % edX" indicates
Byte data is extended by byte to long characters, and the calculation result is stored in the register EDX. The following are some permitted operations:
Extension Suffix:
BL: byte-> long character
BW: byte-> word
WL: Word-> long word
 
The suffix after the jump instruction number indicates the jump direction, "F" indicates the forward (forward), and "B" indicates the backward (back ).
Example: JMP 1f
1: JMP 1f

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.