Mix ANSI C & Asm Part-1 Transform between MASM & AS
2006-03-10 13:31
239 查看
Mix ANSI C & Asm
Part-1
Transform between
MASM & AS
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
E.g.
push $4 ; AT&T syntax
push 4 ; Intel syntax
E.g.
push %ebp ; AT&T syntax
push ebp ;Intel syntax
E.g.
add $4, %eax ; AT&T syntax
add eax, 4 ; Intel syntax
E.g.
movb FOO, %eax ; AT&T syntax
mov eax, byte ptr FOO ; Intel syntax
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
Part-1
Transform between
MASM & AS
Table of Contents
Table of Contents. 2Schema. 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
Schema
The GNU Assembler (as.exe) accepts AT&T syntax, which is difference from Intel syntax that MASM accepts.1. AT&T syntax vs. Intel syntax
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
Appendix
You can use Ta2as/Intel2gas converter convert Intel syntax based source to AT&T syntax based source.相关文章推荐
- Mix ANSI C & Asm Part-2 Using MS C/C++ & MASM
- 创建ASM磁盘时报:Marking disk "VOL1" as an ASM disk:[FAILED]
- H.264/MPEG-4 Part 10 White Paper 译(四) Transform & Quantization(上)
- H.264/MPEG-4 Part 10 White Paper 译(四) Transform & Quantization
- H.264/MPEG-4 Part 10 White Paper 译(四) Transform & Quantization(中)
- the collation conflict between "chinese_prc_ci_as" and "sql_latin1_general_cp1_ci_as" in the equal t
- AS4 下安装Oracle 10g(ASM & RAW)
- [FAILED]Marking disk "DATA02" as an ASM disk
- H.264/MPEG-4 Part 10 White Paper 译(四) Transform & Quantization
- 'Agent XPs' component is turned off as part of the security configuration for this server
- H.264/MPEG-4 Part 10 White Paper 译(四) Transform & Quantization(下)
- Cannot resolve the collation conflict between "Chinese_PRC_CI_AS" and "Chinese_Taiwan_Stroke_CI_AS"
- Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AI"
- DIFFERENCES BETWEEN PROCESSES, SESSIONS AND CONNECTIONS", version 8.1.7.4
- android中遇到java.lang.NumberFormatException: unable to parse 'null' as integer此类问题的原因及解决方法
- 动态代理 jdk as cglib asm
- { Cracking The Coding Interview: 150 programming Q&A } 5th edition Part II
- vb用户定义类型未定义: Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long ;
- PM2 - Documentation - (Install as .deb & Download as ZIP & Contributing - 贡献)
- The user specified as a definer ('root'@'') does not exist when