Summary of at&t assembly instructions

Source: Internet
Author: User

1. Register reference
The reference register must be preceded by a percent sign (%), for example, "movl % eax, % EBX ".
80386 has the following registers:
8 32-bit registers % eax, % EBX, % ECx, % edX, % EDI, % ESI, % EBP, % ESP;
Eight 16-bit registers are actually the 16-bit low of the Eight 32-bit registers above:
% Ax, % BX, % CX, % dx, % Di, % Si, % bp, % sp;
8 8-bit registers % ah, % Al, % BH, % BL, % CH, % Cl, % DH, % DL.
They are in fact the registers % ax, % BX, % CX, % dx of the high 8-bit and low 8-bit;
6 segment registers % CS (CODE), % DS (data), % SS (stack), % es, % FS, % GS;
Three control registers % Cr0, % CR2, % 3303;
6 Debug Registers % db0, % db1, % DB2, % db3, % db6, % db7;
2 test registers % tr6, % tr7;
8 floating point register stacks % ST (0), % ST (1), % ST (2), % ST (3), % ST (4 ), % ST (5), % ST (6), % ST (7 ).
2. operand order
Operands are arranged from the source (left) to the target (right), such as "movl % eax (source), % EBX (destination )"
3. Immediate count
To use the immediate number, add the symbol $
For example, "movl $0x04, % EBX"
Or:
Para = 0x04
Movl $ para, % EBX
The result of the command execution is to load the register EBX for a few hours.
4. symbol Constants
Symbol constants are directly referenced, as shown in figure
Value:. Long 0x12a3f2de
Movl value, % EBX
The command execution result is to load the constant 0x12a3f2de into the register EBX.
The referenced symbolic address is preceded by the symbol $. For example, "movl $ value, % EBX" is used to load the symbolic value address to the storage.
EBX.
5. The length of the operand
The length of the operand is represented by the symbol after the instruction, which is B (byte, 8-bit), w (word, 16-bits), L
(Long, 32-bits), such as "movb % Al, % Bl", "movw % ax, % BX", "movl % eax, % EBX ".
If the length of the operand is not specified, the compiler will set it according to the length of the target operand. For example, the command "mov %
Ax, % BX ", because the length of the target operand BX is word, the compiler will equate this instruction with" movw % ax, %
BX ". Similarly, the command "mov $4, % EBX" is equivalent to the command "movl $4, % EBX", and "Push % Al" is equivalent
In "pushb % Al ". The compiler reports an error for an instruction that does not specify the length of an operand but cannot be guessed by the compiler,
For example, the command "Push $4 ".
6. symbol extension and zero extension commands
The vast majority of at&t Assembly commands for 80386 are the same as Intel-formatted Assembly commands, symbol extension commands and
Zero-extension commands are only commands in different formats. The length and purpose of the source operand must be specified for the symbol extension commands and zero extension commands.
The length of the operand, even if these operands are implicit in some commands.
In at&t syntax, the format of symbol extensions and zero-extension commands is: basic sections "movs" and "movz" (corresponding to intel
Movsx and movzx), followed by the length of the source and target operands. Movsbl means movs (from)
Byte (to) long; movbw means movs (from) byte (to) word; movswl means
Movs (from) Word (to) Long. The same applies to movz commands. For example, the command "movsbl % Al, % edX" means
Extend the content of the Al register and place it in the edX register.
 
Other intel-format symbol extension Commands include:
CBW -- sign-extend byte in % Al to word in % ax;
Cwde -- sign-extend word in % ax to long in % eax;
CWD -- sign-extend word in % ax to long in % DX: % ax;
CDQ -- sign-extend DWORD in % eax to Quad in % edX: % eax;
The command for the corresponding at&t syntax is cbtw, cwtl, cwtd, cltd.
7. Call and redirect commands
The call and redirect commands in segments are "call", "RET", and "JMP", and the inter-segment call and redirect commands are
"Lcall", "LRET", and "ljmp ".
The format of Inter-segment call and jump commands is "lcall/ljmp $ section, $ offset", while the Inter-segment return command is
"LRET $ stack-adjust ".
8. prefix
The operation code prefix is used in the following situations:
Repeated string operation commands (REP, repne );
Specifies the operation segment (CS, DS, SS, es, FS, GS );
Locks the bus );
Specify the address and operation size (data16, addr16 );
In at&t Assembly syntax, the operator code prefix is usually placed in a single row without any operands. For example
The SCAs command is written as follows:
Repne
SCAs
The meanings and usage of the prefix are as follows:
Specify the prefix of the operated segment as CS, DS, SS, es, FS, and Gs. In at&t syntax, you only need to follow
Section: the format of memory-operand specifies the segment prefix. For example: lcall %: realmode_swtch
Operand/address size
The prefixes are "data16" and "addr16". They are used to specify 16-bit operations in 32-bit operands/address code.
Operation/address.
The bus locks the prefix "Lock" to ensure that everything is disabled during the current command execution in a multi-processor environment.
Disconnected. This prefix only applies to add, ADC, And, BTC, BTR, BTS, cmpxchg, Dec, Inc, neg, not,
Or, SBB, sub, XOR, xadd, and xchg commands are valid. If you use the lock prefix before other commands
.
The prefix "Rep", "repe", and "repne" for repeated string operations is "% ECx.
9. Memory Reference
The indirect memory reference format of Intel syntax is:
Section: [base + Index * scale + displacement]
The corresponding form in at&t syntax is:
Section: displacement (base, index, scale)
Base and index are any 32-bit base and index registers. The scale value can be 1, 2, or 8. If no
If the scale value is specified, the default value is 1. Section can specify any segment register as the segment prefix. The default segment register is
Different situations are different. If you specify the default segment prefix in the instruction, the compiler will not generate this
Segment Prefix code.
If the prefix "*" is specified before the call and jump operations, it indicates an absolute address to call/redirect, that is, the JMP/call command specifies an absolute address. If "*" is not specified, the operand is a relative address.
If the operand of any instruction is a memory operation, the instruction must specify its operation size (byte, word, long), that is, it must carry the instruction suffix (B, W, L ).

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.