AT & amp; T assembly language-Composition of tools and programs

Source: Internet
Author: User

1. Development Tools

In assembly languages, the tools used mainly use the following:

Assembler, connector, debugger, Compiler

Because I am here using AT&T assembly language, the tools are also under gnu.


1.1 assembler ()

There are many assembler tools, such as masm, nasm, and gas. Unlike advanced languages, although they are all called assembly languages, their syntax is quite different for different compilers. Intel compiled books are everywhere, but there are few AT&T books. But if you want to see the Linux kernel, you still need to be familiar with AT&T assembly. This may be why I learned the compilation. When it comes to assembler, we use as, which has many optional parameters, but we use several:

For example, we want to compile test. s for the test. o of the ia-32 platform,

$ as  --32  -o test.o test.s
Here we only use two parameters -- 32 and-o

-- 32: Is the code specified as a ia-32 platform,

-O: returns the target file.


1.2 connector (ld)

The following parameters are used:

-M elf_i386: connect the target code to the elf_i386 format (that is, the code on the 32-bit platform)

-O: returns the target file.

 

1.3 debugger (gdb)

The main Commands are:

List: lists the specified functions or rows.

Break: sets a breakpoint.

Run: run

Next: next command

Step: Execute the next instruction in the program


1.4 Compiler (gcc)

Pure assembly does not require gcc. There are not many gcc parameters used, including the following:

-G: code in debugging mode

-O: followed by the target code

-M32: generate the ia32 platform code


1.5 Other Tools

1.5.1 objdump

Objdump is a very useful tool that implements disassembly.

The main parameters used are:-d, which indicates to decompile the target code into a script code.

 

1.5.2 gprof

Gprof prints the time consumed by each function in the program running, and helps the programmer find the most time-consuming function among the many functions.

 

1.5.3 operating system linux

My testing environment is ubuntu 14.04 (x86_64), but I learned only ia-32-bit assembly, so use -- 32,-m32,-m elf_i386 to generate 32-bit code

 

2. Sample assembly language templates

In fact, there are very few programs developed simply by using assembler. I learned this for two purposes:

1. Understand the code in the Linux Kernel

2. Understand the assembly code generated by C/C ++ and other programs.

 

Therefore, I hope that the Assembly format can be directly linked to the C language.

 

2.1 assembly program composition

An assembly language consists of defined segments, each of which has different purposes. The three common sections are as follows:

Data Segment (. section. data)

Declares data elements with initial values as variables in assembly language programs.

Bss section (. section. bss. How can I translate Chinese Characters ?)

Usage buffer zone of Assembly Language

Text section (. section. text)

Store code

 

2.1.1 definition section method

The GNU assembler uses the. section command statement to declare a segment .. The section statement uses a parameter-the type of the declared section. As shown in the following figure. This will be the layout we will use in the future.

 

 

2.1.2 start point of the definition segment

When an assembly language program is converted to an executable file, the connector must know the starting point. The gnu assembler declares a default label _ start, indicating that the program starts from this command. Of course, you can also use the connector parameter-e to define a new start name.

Well, let's summarize the basic templates of our assembly language:

. Section. data <put data with initial values here>. section. bss <uninitialized values here>. section. text. globl _ start_start: <run code here>

Let's write this article today. Let's talk about the usage of the tool today with a specific example tomorrow.

 

 

 

 

 

 

 


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.