In the Linux environment, the compilation language programming preliminary -- AT & amp; T Syntax -- Linux general technology-Linux programming and kernel information. The following is a detailed description. I am currently studying Linux assembly and writing articles to share my experiences
As an efficient programming language that closely integrates with the hardware platform, assembly language plays an important role in operating systems, embedded development, and other fields. Because Assembly depends on the hardware structure (CPU instruction code), the assembly languages in different architectures are also quite different. At present, most of the compilation language courses in Chinese universities are presented in the Intel Platform syntax format, and few books on other architecture assembly languages are available on the market, this makes it very difficult for system programmers to study compilation code on other platforms. This article briefly introduces the AT&T syntax in Linux and the basic methods for compiling in Linux.
AT&T syntax originated from the AT&T Bell lab and was formed based on the processor operation code syntax used to implement Unix systems at that time. The main differences between AT&T syntax and Intel syntax are as follows:
AT&T uses $ to represent the immediate number, Intel does not, so it indicates that in decimal 2, AT&T is $2, while Intel is 2
AT&T adds % before the register. For example, the eax register is % eax.
AT&T processes operands in the opposite order of Intel. For example, movl % eax and % ebx pass values in eax to ebx, while Intel is mov ebx and eax.
AT&T adds a separate character to the mnemonic to indicate the length of data in the operation. For example, movl $ foo and % eax are equivalent to mov eax and word ptr foo of Intel.
The long jump and call formats are different. AT&T is ljmp $ section, $ offset, and Intel is jmp section: offset.
The main difference is that there are many other details. Here is a specific example to illustrate.
CODE: # cpuid. s Sample program
. Section. data
Output:
. Ascii "The processor Vendor ID is 'xxxxxxxxxxxx' \ n"
. Section. text
. Globl _ start
_ Start:
Movl $0, % eax
Cpuid
Movl $ output, % edi
Movl % ebx, 28 (% edi)
Movl % edx, 32 (% edi)
Movl % ecx, 36 (% edi)
Movl $4, % eax
Movl $1, % ebx
Movl $ output, % ecx
Movl $42, % edx
Int $0x80
Movl $1, % eax
Movl $0, % ebx
Int $0x80 |