Intel and AT&T Syntax

本文详细对比了Intel与AT&T两种汇编语言语法的主要差异,包括前缀使用、操作数方向、内存操作数表示及指令复杂度等方面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Intel and AT&T Syntax.

Intel and AT&T syntax Assembly language are very different from eachother in appearance, and this will lead to confusion when one first comesacross AT&T syntax after having learnt Intel syntax first, or vice versa.So lets start with the basics.

Prefixes.

In Intel syntax there are no register prefixes or immed prefixes. InAT&T however registers are prefixed with a '%' and immed's are prefixedwith a '$'. Intel syntax hexadecimal or binary immed data are suffixed with 'h'and 'b' respectively. Also if the first hexadecimal digit is a letter then thevalue is prefixed by a '0'.

Example:

Intex Syntax

mov     eax,1
mov     ebx,0ffh
int     80h

AT&T Syntax

movl    $1,%eax
movl    $0xff,%ebx
int     $0x80

Direction of Operands.

The direction of the operands in Intel syntax is opposite from that ofAT&T syntax. In Intel syntax the first operand is the destination, and thesecond operand is the source whereas in AT&T syntax the first operand isthe source and the second operand is the destination. The advantage of AT&Tsyntax in this situation is obvious. We read from left to right, we write fromleft to right, so this way is only natural.

Example:

Intex Syntax

instr   dest,source
mov     eax,[ecx]

AT&T Syntax

instr   source,dest
movl    (%ecx),%eax

Memory Operands.

Memory operands as seen above are different also. In Intel syntax the baseregister is enclosed in '[' and ']' whereas in AT&T syntax it is enclosedin '(' and ')'.

Example:

Intex Syntax

mov     eax,[ebx]
mov     eax,[ebx+3]

AT&T Syntax

movl    (%ebx),%eax
movl    3(%ebx),%eax 

The AT&T form for instructions involving complex operations is veryobscure compared to Intel syntax. The Intel syntax form of these issegreg:[base+index*scale+disp]. The AT&T syntax form is %segreg:disp(base,index,scale).

Index/scale/disp/segreg are all optional and can simply be left out. Scale,if not specified and index is specified, defaults to 1. Segreg depends on theinstruction and whether the app is being run in real mode or pmode. In realmode it depends on the instruction whereas in pmode its unnecessary. Immediatedata used should not '$' prefixed in AT&T when used for scale/disp.

Example:

Intel Syntax

instr   foo,segreg:[base+index*scale+disp]
mov     eax,[ebx+20h]
add     eax,[ebx+ecx*2h
lea     eax,[ebx+ecx]
sub     eax,[ebx+ecx*4h-20h]

AT&T Syntax

instr   %segreg:disp(base,index,scale),foo
movl    0x20(%ebx),%eax
addl    (%ebx,%ecx,0x2),%eax
leal    (%ebx,%ecx),%eax
subl    -0x20(%ebx,%ecx,0x4),%eax

As you can see, AT&T is very obscure. [base+index*scale+disp] makes moresense at a glance than disp(base,index,scale).

Suffixes.

As you may have noticed, the AT&T syntax mnemonics have a suffix. Thesignificance of this suffix is that of operand size. 'l' is for long, 'w' isfor word, and 'b' is for byte. Intel syntax has similar directives for use withmemory operands, i.e. byte ptr, word ptr, dword ptr. "dword" ofcourse corresponding to "long". This is similar to type casting in Cbut it doesnt seem to be necessary since the size of registers used is theassumed datatype.

Example:

Intel Syntax

mov     al,bl
mov     ax,bx
mov     eax,ebx
mov     eax, dword ptr [ebx]

AT&T Syntax

movb    %bl,%al
movw    %bx,%ax
movl    %ebx,%eax
movl    (%ebx),%eax

 


ref[1]: http://www.imada.sdu.dk/Courses/DM18/Litteratur/IntelnATT.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值