AT&T汇编语言语法

本文详细介绍了AT&T汇编语言的语法,包括寄存器引用、操作数顺序、立即数操作、符号常数、操作数长度、符号和零扩展,以及调用和跳转指令的使用。通过实例解析了如何进行寄存器操作和数据传输,帮助读者掌握这种汇编语言的特点。

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

AT&T汇编语言语法

1.Register Reference
 引用寄存器要在寄存器号前加百分号%,如“movl %eax, %ebx”。
 80386 有如下寄存器:
[1] 8 个32-bit 寄存器 %eax,%ebx,%ecx,%edx,%edi,%esi,%ebp,%esp;
( 8 个16-bit 寄存器,它们事实上是上面8 个32-bit 寄存器的低16 位:%ax,%bx,
%cx,%dx,%di,%si,%bp,%sp;
 8 个8-bit 寄存器:%ah,%al,%bh,%bl,%ch,%cl,%dh,%dl。它们事实上
是寄存器%ax,%bx,%cx,%dx 的高8 位和低8 位;)
[2] 6 个段寄存器:%cs(code),%ds(data),%ss(stack), %es,%fs,%gs;
[3] 3 个控制寄存器:%cr0,%cr2,%cr3;
[4] 6 个debug 寄存器:%db0,%db1,%db2,%db3,%db6,%db7;
[5] 2 个测试寄存器:%tr6,%tr7;
[6] 8 个浮点寄存器栈:%st(0),%st(1),%st(2),%st(3),%st(4),%st(5),%st(6),%st(7)。

2. Operator Sequence
操作数排列是从源(左)到目的(右),如“movl %eax(源), %ebx(目的)”

3. Immediately Operator
使用立即数,要在数前面加符号$, 如“movl $0x04, %ebx”
或者:
para = 0x04
movl $para, %ebx
指令执行的结果是将立即数0x04 装入寄存器ebx。

4. Symbol Constant
符号常数直接引用 如
value: .long 0x12a3f2de
movl value , %ebx
指令执行的结果是将常数0x12a3f2de 装入寄存器ebx。
引用符号地址在符号前加符号$, 如“movl $value, % ebx”则是将符号value 的地址装入寄存器ebx。

5. Length of Operator
操作数的长度用加在指令后的符号表示b(byte, 8-bit), w(word, 16-bits), l(long,32-bits),如“movb %al, %bl”,“movw %ax, %bx”,“movl %eax, %ebx ”。
如果没有指定操作数长度的话,编译器将按照目标操作数的长度来设置。比如指令“mov %ax, %bx”,由于目标操作数bx 的长度为word,那么编译器将把此指令等同于“movw %ax,%bx”。同样道理,指令“mov $4, %ebx”等同于指令“movl $4, %ebx”,“push %al”等同于“pushb %al”。对于没有指定操作数长度,但编译器又无法猜测的指令,编译器将会报错,比如指令“push $4”。

6. Sign and Zero Extension
绝大多数面向80386 的AT&T 汇编指令与Intel 格式的汇编指令都是相同的,但符号扩展指令和零扩展指令有不同格式。符号扩展指令和零扩展指令需要指定源操作数长度和目的操作数长度,即使在某些指令中这些操作数是隐含的。
     在AT&T 语法中,符号扩展和零扩展指令的格式为,基本部分"movs"和"movz"(对应Intel 语法的movsx 和movzx),后面跟上源操作数长度和目的操作数长度。movsbl 意味着movs (from)byte (to)long;movbw 意味着movs (from)byte (to)word;movswl意味着movs (from)word (to)long。对于movz 指令也一样。比如指令“movsbl %al,%edx”意味着将al 寄存器的内容进行符号扩展后放置到edx 寄存器中。

其它的Intel 格式的符号扩展指令还有:
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;
对应的AT&T 语法的指令为cbtw,cwtl,cwtd,cltd。

7. Call and Jump
段内调用和跳转指令为"call","ret"和"jmp",段间调用和跳转指令为"lcall","lret"和
"ljmp"。段间调用和跳转指令的格式为“lcall/ljmp $SECTION, $OFFSET”

 


本书为 TNT DOS-Extender 8.0 的参考手册之一。 386|ASM Reference Manual (386|ASM 宏汇编参考工具) Phar Lap 的宏汇编语言的 x86 系列微处理器的技术参考书。 ---------------------------------------------------------- 欢迎使用 TNT DOS-Extender 和 TNT Realtime DOS-Extender,这是 Phar Lap 的最新的那个年代曾经屡获殊荣 DOS 扩展器技术! 这个产品为运行在 MS-DOS 或 PC-DOS 的程序提供了32位 x86 保护模式运行环境。 TNT Realtime DOS-Extender 支持DOS下多线程序的运行时程序。 TNT DOS-Extender Reference Manual 参考手册详细介绍了应用程序需要的保护模式环境。 System Requirements 386, 486, Pentium 或更高处理器 2 MB 扩展内存 10 MB 剩余硬盘空间 MS-DOS 3.0 或以上版本 32-bit C/C++编译链接工具,可使用 Borland C++、Visual C++、Watcom C/C++、Open Watcom C/C++(推荐)等32位编译工具 TNT DOS-Extender 可以使用下面的编译和链接工具的组合: Microsoft Visual C/C++ for Windows and Windows NT, 32位版本编译器和链接器 (CL and LINK) Microsoft Visual C/C++ for Windows and Windows NT, 32版本编译器和Phar Lap连接器(TNT链接器) (CL and 386LINK) MetaWare High C/C++ 编译器和Phar Lap连接器(TNT链接器) (HC386 and 386LINK) Open-Watcom C/C++32 编译器和Phar Lap连接器(TNT链接器) (WCC386 and 386LINK) TNT DOS-Extender 包括下面的文档 TNT DOS-Extender Reference Manual(参考手册) 保护模式环境详细介绍(各种参数)、编程介绍 C/C++ User’s Guide to TNT DOS-Extender (用户指南) A tutorial style guide to developing C and C++ programs for TNT DOS-Extender, including instructions for building programs using the Microsoft Visual C/C++ for Windows and Windows NT, 32-bit Edition compiler, the MetaWare High C/C++ compiler, and the WATCOM C/C++32 compiler. Libraries and System Calls Reference (库和系统调用参考) Complete documentation on the C-callable TNT DOS-Extender system calls in DOSX32.LIB, the C-callable MS-DOS and BIOS system calls in DOS32.LIB, the C-callable NtStyle Win32 API subset, and the register-based software interrupt interface for TNT DOS-Extender, MS-DOS, and BIOS system calls. Utilities Reference Manual (工具参考手册) A reference on the utility programs included with the TNT DOS-Extender SDK, including: the 386|LINK linker; the 386|LIB librarian; the REBIND binder utility program; the PLSTRIP symbol table strip utility; the CFIG386 configuration utility; the MAPEXE executable file dump program; and the TELLME system report utility. Windows Interface Guide (Windows 界面向导) A description of the Phar Lap WinPipe Application Program Interface (API) and a tutorial on using this API to build a Windows 3.1 graphical user interface for your TNT DOS-Extender program. CodeView Reference Manual (CodeView 调试参考手册) A reference for using the CodeView source code debugger to debug 32-bit protectedmode programs. 386|SRCBug Reference Manual (TNT 386|SRCBug 调试器参考手册) Documentation for the Phar Lap source code debugger, including debugger commands, protected-mode debugging, and a sample debug session. 386|ASM Reference Manual (386|ASM 宏汇编参考工具) A technical reference for Phar Lap’s assembler for Intel 8086 and later microprocessors.
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值