Mix ANSI C & Asm Part-1 Transform between MASM & AS

Mix ANSI C & Asm

Part-1

Transform between

MASM & AS

 


Table of Contents. 2

Schema. 3

1. AT&T syntax vs. Intel syntax. 3

1.1 Immediate operand. 3

1.2 Register operand. 3

1.3 Source & Destination operand. 3

1.4 Memory operand. 3

1.5 Long jump/call/return. 4

1.6 Indirect memory reference. 4

Appendix. 4

 


The GNU Assembler (as.exe) accepts AT&T syntax, which is difference from Intel syntax that MASM accepts.

You can type info as machine i386 for complete description.

1.1 Immediate operand

AT&T immediate operand are proceed by $; Intel immediate operand are unlimited.

E.g.

push  $4          ; AT&T syntax

push  4           ; Intel syntax

1.2 Register operand

AT&T register operand are proceed by %; Intel register operand are unlimited.

E.g.

push  %ebp        ; AT&T syntax

push  ebp         ;Intel syntax

1.3 Source & Destination operand

AT&T and Intel syntax use the opposite order for source and destination operands.

E.g.

add   $4,   %eax        ; AT&T syntax

add   eax,  4           ; Intel syntax

1.4 Memory operand

In AT&T syntax, the size of memory operand is determined from the last character of the opcode name. Opcode suffixes of b, w and l specify byte (8-bits), word (16-bits) and long (32-bits) memory reference. Intel syntax accomplishes this by prefixing memory operand with byte ptr, word ptr and dword ptr.

E.g.

movb  FOO,        %eax              ; AT&T syntax

mov   eax,        byte ptr FOO            ; Intel syntax

1.5 Long jump/call/return

Immediate form long jumps and calls are lcall/ljmp $SECTION, $OFFSET in AT&T syntax; The Intel syntax is call/jmp far SECTION:OFFSET. Also, the far return instruction is lret $STACK-ADJUST in AT&T syntax, Intel syntax is ret far STACK-ADJUST.

1.6 Indirect memory reference

In AT&T  the form of indirect memory reference is : SECTION:DISP(BASE, INDEX, SCALE); Intel syntax is : SECTION:[BASE + INDEX*SCALE + DISP].

E.g.

-4(%ebp)                ; AT&T syntax

[ebp + 4]               ; Intel syntax

 

foo(, %eax, 4)          ; AT&T syntax

[foo + ebp*4]           ; Intel syntax

 

foo(, 1)                ; AT&T syntax

[foo]                   ; Intel syntax

 

%gs:foo                 ; AT&T syntax

gs:foo                  ; Intel syntax

You can use Ta2as/Intel2gas converter convert Intel syntax based source to AT&T syntax based source.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值