Linux assembly language programming preliminary -- AT&T syntax

Source: Internet
Author: User
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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.