Article Two: Understanding ISA(Instruction Set Architecture)
Key Concepts:
- "ISA"
- "IA-32": Intel changed the name of the 32-bit x86 architecture x86-32 to IA-32, a common Isa
- "Memory Model"
- "Procedure Call"
Isa (Instruction Set Architecture) is located between software and hardware
• Hardware features are provided via ISA
• The software uses the hardware through the "directives" specified by Isa
the Isa stipulates that:
– The set of executable instructions, including the instruction format, the type of operation, and the corresponding number of operands for each operation;
– The type of operand that the instruction can accept;
– The structure of the register group that the operand can hold, including the name, number, length, and purpose of each register ;
– The size and address of the storage space that the operand can hold ;
– the number of operations stored in storage space in the big or small end of the way ;
– The way the instruction obtains the operand, i.e. the addressing method ;
– The control mode of the instruction execution process, including program counter , condition code definition and so on.
several aspects stipulated by IA-32:
"IA-32 is cisc complex instruction set"
- data structure types and formats supported by IA-32
- Register organization of IA-32
- Flag Register for IA-32
- How to address IA-32
- floating-point register stacks and multimedia extended register groups
- IA-32 Common instruction types
"program conversion and machine-level representation"
Learn about advanced languages and assembly language,
The relationship between assembly language and machine languages
Learn about instruction formats,
Type of operand,
Addressing methods,
Type of operation, and other content
Understanding the correspondence between statements and machine-level code in high-level language source programs
Understanding machine-level implementations of complex data types (arrays, structures, etc.)
0. IA-32 Register Model
"Understand how computers work.
The program is made up of instructions
Before executing the program:
Data and instructions are stored in memory, each instruction and each data has an address, instruction is stored sequentially, the instruction is composed of OP, addr field, program start address pc
(raw materials and recipes are placed on shelves outside the kitchen, with each shelf numbered.) Mom starts by assigning recipes on the 5th shelf)
To start executing the program:
Step one: Take instructions from the PC (take the recipe from rack 5th)
Step Two: Instruction decoding (see recipes)
Step three: Take the operand (take the raw material from the rack or tray)
Fourth Step: Instruction execution (washing, cutting, frying and other specific operations)
Fifth step: Write back the result (plate or direct table)
Sixth step: Modify the value of the PC (figure out the next recipe is the shelf number 6=5+1)
Continue with the next instruction (continue to the next dish)
"☆ Memory model
Author Note:
" different languages have different memory models. Only by mastering the memory model can we really have the basic ability to analyze the time and space efficiency of the program.
such as the compiler language C, C + +, the analysis of them to be combined with compiled assembly language, but also pay attention to the operating system and compiler memory management impact.
further learning is required as to how the operating system and compiler affect the memory model. "
Process Virtual address space.
"Image from Csapp 3rd"
. Heap. The code and data areas is followed immediately by the Run-time heap. Unlike the code and data areas, which is fixed in size once the process begins running, the heap expands and contracts dy Namically at run time as a result of calls to C standard library routines such as malloc and free.
Heap, which holds data that is dynamically created by the program.
. Shared Libraries. The middle of the address space is a area that holds the code and data for shared libraries such as the C standard L Ibrary and the math library. The notion of a shared library is a powerful but somewhat difficult concept.
shared storage area:
static storage: Storing shared data
. Stack. At the top of the user's virtual address space is the user stack, the compiler uses to implement function calls. Like the heap, the user stacks expands and contracts dynamically during the execution of the program. In particular, each time we call a function, the stack grows. Each time we return from a function, it contracts.
Stack: Used for data storage, local variables during program invocation.
. Kernel virtual Memory. The kernel is the part of the operating system, which is always resident in memory. The top region of the address space was reserved for the kernel. Application programs is not allowed to read or write the contents of this area or to directly call functions defined in T He kernel code.
Core Virtual Storage: The operating system private storage area.
"The machine-level representation of the procedure call:
each recursive call adds a stack frame, so the space overhead is high.
The Register use convention of the IA-32
Caller Save Register: EAX, EDX, ECX
When procedure p calls the procedure Q, Q can use the three registers directly without saving their values to the stack. If p is to use these three registers after returning from Q, p should be saved before going to Q and revert to their values before returning from Q.
callee Save Register: EBX, ESI, EDI
Q must first save their values to the stack before using them, and restore their values before returning p.
EBP and ESP are frame pointer registers and stack pointer registers, respectively, to point to the bottom and top of the current stack frame.
"Two ways to pass parameters in a procedure call:
1. Passing by value
2. Pass by address
"Array Assignment and access:
1. Assigning to a static zone
global variables, static data
2. Allocation in the stack, via EBP to locate
local variables, entry parameters
"Stack frames:
Push%EBP
MOV%ESP,%EBP
Each jump executes two-hop statements that make up the bottom of the stack (at high addresses). EBP holds the original EBP value.
"There is time to learn how the program corresponds to the machine instructions, that is compiled into assembly language process."
"Data access:
2, 4 do not have the operation, understand the pointer in improving the efficiency of the performance of the point.
"alignment of the data
the machine word length is a fixed 32-bit or 64-bit. Data is addressed in bytes, and each access may span addresses.
The goal of alignment is to reduce the number of visits and improve time and space efficiency. (after all, the data bus reads several bytes at a time!) )
alignment of the > Data
all types of data in x86-64 follow certain alignment rules and are more stringent
The x86-64 Memory Access interface is designed to be accessed in 8-byte or 16-byte increments, with the alignment rule that the starting address of any K-byte-wide base data type and pointer-type data must be a multiple of K
for example, the int type occupies 4 bytes, and the address can only be located in 0,4,8.
> Alignment:
#pragma pack (n)
• Specifies the alignment of member variables within the struct or class for the compiler.
• when the natural boundary (such as int type is 4 bytes, short type by 2 bytes, float by 4 bytes) is larger than N, the N-byte alignment.
• Default or #pragma pack () , aligned by natural boundary.
__attribute__ ((aligned (m) )
• Specifies the alignment of a struct or class or union or a separate variable (object) for the compiler.
• by M-byte alignment (M must be power of 2), and its footprint is an integer multiple of M, to ensure that each element is also aligned in M-byte when applying for contiguous storage space.
__attribute__ ((packed))
l do not align to boundaries, called compact mode.
different operating system alignment policies may vary. The memory utilization efficiency that causes the different structure declaration order is different.
WINDOSWS Policy:
Linux Policies:
{
waiting to be added ~
}
Ps: After learning this, you can prepare for the buffer overflow behind.
Let me summarize:
from the above content can be seen, people do a lot of work to reduce the number of visits, improve the system's time and space efficiency. Because of the overhead of accessing the memory compared to the access register.
Note that the software can also take many effective measures to reduce the number of visits.
A variety of addressing methods are also designed to accommodate the needs of data types in high-level languages.
Reprint Please specify Source: http://www.cnblogs.com/learn-to-rock/p/5876337.html
"In-depth understanding of computer system 02" ISA and Memory model