汇编学习笔记
RAX,EAX,AX,AH,AL
RAX是64位的寄存器
EAX是32位的寄存器,而AX是EAX的低16位。
AH是AX的高8位,而AL是AX的低8位
操作数前缀
1 | movl $8,%eax |
看到在AT%T汇编中诸如”%eax”、”%ebx”之类的寄存器名字前都要加上”%”;”$8”、”$0xffff”这样的立即数之前都要加上”$”。
源/目的操作数顺序
在Intel语法中,第一个操作数是目的操作数,第二个操作数源操作数。而在AT&T中,第一个数是源操作数,第二个数是目的操作数。
1 | // INTEL语法 |
标识长度的操作码后缀
在AT&T的操作码后面有时还会有一个后缀,其含义就是指出操作码的大小。“l”表示长整数(32位),“w”表示字(16位),“b”表示字节(8位)。1
2
3
4movb %bl,%al
movw %bx,%ax
movl %ebx,%eax
movl (%ebx),%eax
Labels
A label can be placed at the beginning of a statement. During assembly, the label is assigned the current value of the active location counter and serves as an instruction operand. There are two types of lables: symbolic and numeric.
Symbolic Labels
A symbolic label consists of an identifier (or symbol) followed by a colon (:) (ASCII 0x3A). Symbolic labels must be defined only once. Symbolic labels have global scope and appear in the object file’s symbol table.
Symbolic labels with identifiers beginning with a period (.) (ASCII 0x2E) are considered to have local scope and are not included in the object file’s symbol table.
Numeric Labels
A numeric label consists of a unsigned decimal int32 value followed by a colon (:). Numeric labels are used only for local reference and are not included in the object file’s symbol table. Numeric labels have limited scope and can be redefined repeatedly.
When a numeric label is used as a reference (as an instruction operand, for example), the suffixes b
(“backward”) or f
(“forward”) should be added to the numeric label. For numeric label N, the reference Nb
refers to the nearest label N defined before the reference, and the reference Nf
refers to the nearest label N defined after the reference. The following example illustrates the use of numeric labels:
1 | 1: / define numeric label "1" |
参考资料: