Linux Kernel Programming Study Notes 1: AT, T Assembly Language
Source: Internet
Author: User
Linux Kernel Programming Study Notes 1: AT, T assembly language-general Linux technology-Linux programming and kernel information, the following is a detailed description. I started to learn Linux kernel programming today. I have never started to learn kernel programming basics. Therefore, we need to understand a lot of relevant knowledge. The first is AT&T assembly language. Because in the Linux kernel source code, it seems that apart from the start bootsect. s and head. s is an intel assembly, and other assembly code is an AT&T assembly language, so it is necessary to understand AT&T assembly language.
However, since AT&T compilation is similar to intel compilation, you can find out some differences.
The following are the features of AT&T assembly:
1. Add "%" before the Register, such as mov % eax and % ebx.
Note that in AT&T assembly, the source register and destination register are in the opposite order of intel assembly. In AT&T assembly, the source register is on the left and the target register is on the right, in the above example, % eax is the source register and % ebx is the destination register.
2. Add $ before the number of immediate constants, such as mov $4 and % ebx to load the number 4 into the ebx register.
Symbol constants are directly used. For example, mov value and % eax load the value represented by value into the eax register.
Mov $ value, % eax uses the value of value as the address, and loads the value in the corresponding address into eax.
3. B (byte): 8 bits, w (word): 16 bits, l (long): 32 bits
For example: movb % ax, % bx movw % eax, % ebx
4. Add "*" as the prefix before the jum/call operations to jump to ljmp and call lcall
For example, ljmp $ section and $ offset
Lcall $ section, $ offset
Here, $ section and offset indicate that section is the segment address and offset is the intra-segment offset address. Therefore, ljmp $ section and $ offset jump to section: offset address.
5. Return lret far
For example, lret $ stack_adjust
6. Addressing Mode
Section: disp (base, index, scale)
Calculation method base + index * scale + disp
Section: [base + index * scale + disp]
Disp indicates the offset address.
For example movl-4 (% ebp), % eax loads the content of [% ebp-4] into eax
7. C language Embedded Assembly
Format: _ asm _ ("asm statements": outputs: inputs: registers-modified)
Among them, "asm statements" is an assembly statement expression, outputs, inputs, and register-modified are optional parameters, separated by colons, and 0 ~ 9. For example, the outputs register is 0, the inputs register is 1, and so on. Outputs is the register output after the Assembly statement is executed, and inputs is input to a register.
Example 1: _ asm _ ("pushl % eax \ n \ t" "movl $0, % eax \ n \ t" "popl % eax ");
In the Embedded Assembly, two % should be added before the register. Because gcc is compiling, a % will be removed first and then output to the Assembly format.
Example 2: {register char _ res ;\
Asm ("push % fs \ n \ t"
"Movw % ax, % fs \ n \ t"
"Movb % fs: % 2, % al \ n \ t"
"Pop % fs"
: "= A" (_ res): "0" (seg), "m" (* (addr )));\
_ Res ;}
In the movb % fs: % 2, % al \ n \ t clause, the second register, that is, the value in the subsequent seg, is the value corresponding to the offset address and is loaded into al. "= A" (_ res): "0" (seg), "m" (* (addr), "= a" (_ res) indicates that the content in register a is given to _ res, and "0" (seg) indicates that the content in seg is given to the Register corresponding to 0, 0 indicates that the Register is the same as the previous one. Here, register a is used, that is, the content of the seg is a register.
It must be explained that a, B, c, and d indicate the registers eax, ebx, ecx, and edx respectively.
S and D indicate the registers esi and edi respectively.
R indicates any register
0 (number 0, not o !) Indicates that the previous register is used.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service