Linux compilation-Memoirs One

Source: Internet
Author: User

= = = Compilation Basis = =
The assembly language program is composed of well-defined segments, commonly used in three segments:
Data element for the initial value of the data segment
BSS segment uses 0 initialized data elements
Text Snippet Program code

Indicate:
The data declared in the BSS segment is not included in the executable program, but
Data segments must be included in the section execution program

The preparation of the compendium has the following rules:
Define segments using the. Section pseudo-directive definition)
Defines the entry point using the. globl pseudo-directive definition, which identifies the program from which
Start the execution of the program, the general default is. Global _start
If GCC is compiled, it is defined as. globl Main

= = Assembly pseudo-directive = = =
. section indicates which type of program segment to use
. Data indicates a segment
. text indicates a code snippet
. GLOBL marking the entry point of the program
. equ defines a static symbol, typically referenced in a text segment (using the $ symbol reference)
. comm declared as a common memory area of the initialized data
. Lcomm local memory area declared as initialized data

Pseudo-directive. Comm,. Lcomm both formats are similar to ". Comm Symbol, Length"

= = = Data type directive = = =
. Long Long Integer
. Byte byte value
. int integral type
. ASCII strings
. Asciz string ending with a null character
. Double double-precision floating-point numbers
. Float single-precision floating-point number
. octa 16-byte integer
. Quad 8-byte integer
. short 16-bit integers

= = = Assembly Stack frame = = =
assembly language uses tags to identify addresses, examples are as follows
Label_name:
Assemble code
...

The stack has a term that needs to be familiar. One is the bottom of the stack, which represents the starting position of the stack, in the high
The other is the top of the stack, the top of the stack represents the current location of the stack, at the low address, the data constantly
Into the stack, out of the stack, so that the top of the stack has been active, but also need to know that the growth of the stack is to low
Address aspects

Standard-setting,%ESP register holds the stack-top pointer,%EBP register holds the stack-bottom pointer, these two registers can only
It is unwise to use it for any other purpose.

= = = = = = = =
Direct addressing mode
EXP:MOVL ADDRESS,%eax

Variable address addressing mode
Exp:movl Address_start (,%ecx,1),%eax

Indirect addressing mode
EXP:MOVL (%eax),%EBX
# The value of%EBX is an address

Base Address mode
EXP:MOVL 4 (%eax),%EBX

Immediate number addressing
EXP:MOVL,%eax

Register addressing
EXP:MOVL%eax,%EBX

The addressing method can be outlined as the following formula:
Address_or_offset (%base_or_offset,%index,multiplier)
FINAL ADDRESS = address_or_offset +%base_or_offset + MULTIPLIER *%index
Description
1.address_or_offset and multiplier must be constants
2. The remaining two must be registers, and if a value is empty, leave the line blank

= = = Assembly Instruction = = =
Not all listed here, listing what you have learned

The 1.cmpl instruction compares two numbers and sets the value of the%eflags register, which is then used by the following jump instruction
Compare instruction format cm Operand1, operand2, note the position of the operand, especially with Intel's
Inconsistent syntax

2. Conditional Jump Instruction
Je Equal
JG the second number is greater than the first number
Jge the second number is greater than or equal to the first number
JL second number less than the first number
Jle The second number is less than or equal to the first number
JMP Unconditional Jump

The instruction of the 3.CPUID uses a single register%EAX as input and returns a string with the address from
Low to high storage in%EBX,%ECX,%edx
The value of the%eax
0 Vendor ID String
1 Processor Type
2 Processor Cache Configuration
3 Processor Serial Number
4 Cache Configuration
5 Monitoring information

= = = Jump Branch = =
Jump assembly language must use jump to implement many functions
Use a single instruction in JMP location (typically a label address)
Calls using the call command
Interrupt Soft interrupt + hard Interrupt
Exp1:int 0x80 belongs to soft interrupt
EXP2: Hardware appears to be divisor to zero interrupt program belongs to hard interrupt

Conditional jump
1. Near jump 16 or 32 address offset
2. Short jump 8-bit address offset
3. Memory mode is not supported far jump

= = Assembly function = = =
1. How to define
. type Function_name, @function
Function_name:
Function_code
...

2. Calling assembly functions
Call function_name256

= = = Command-line parameter pass = =
When the Linux program starts, the command line arguments pass the stack frame structure as follows
High Address environment variables
Command-line arguments
Pointers to environment variables
Split 0x00000000
Pointer to command-line parameter n
...
Pointer to command line parameter 2
Pointer to command line parameter 1
Program Name
Number of parameters
...
Description: The number of parameters is never 0, greater than or equal to 1, because the program name always exists

= = = System call = = =
Linux kernel system calls
Call number exists Vim/usr/include/asm/unistd.h

System calls the specified input value method
%eax system call number
%EBX first parameter
%ECX a second parameter
%edx a third parameter
%esi Fourth parameter
%edi Fifth parameter

If there are more than 6 parameters, then%EBX holds the memory location pointer to the input parameter, then the parameter
Memory requires storage continuity, and the return value of the system call is stored in the%EAX register

Inline assembly is embedded using ASM ("ASM Code"), which is free to embed assembly code, but
You cannot use local variables in C code, only global variables

Linux compilation-Memoirs One

Related Article

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.