Mix ANSI C & Asm
Part-1
Transform between
MASM & AS
1. AT&T syntax vs. Intel syntax
1.3 Source & Destination operand
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.