3.1-3.7 in practice, Focus: 3.1,3.3,3.5,3.6,3.9,3.14,3.15,3.16,3.22,3.23,3.27,3.29,3.30,3.33,3.34
p104, p105:x86 addressing mode through three generations:
1 DOS时代的平坦模式,不区分用户空间和内核空间,很不安全 2 8086的分段模式 3 IA32的带保护模式的平坦模式
P106:isa definition, ISA needs everyone can summarize the law, extrapolate, such as can compare to learn arm isa;pc register to understand well;
P107:gcc-s xxx.c-o xxx.s Get assembly code, you can also use objdump-d XXX disassembly; Note that the first two and the last two assembly code, all functions have, build function call stack frame, should understand, memorize.
注意: 64位机器上想要得到32代码:gcc -m32 -S xxx.c MAC OS中没有objdump, 有个基本等价的命令otool Ubuntu中 gcc -S code.c (不带-O1) 产生的代码更接近教材中代码(删除"."开头的语句)
p108: Binary files can be viewed with the Od command, or by GDB's X command. Some of the output is too much, we can use the more or less command to view with a pipe, or you can use output redirection to view
od code.o | more od code.o > code.txt
P109:gcc-s produced in the assembly can be put to "." The start statement is deleted and then read
P110: Understanding the compilation format of Linux and Windows is a bit different: ATT format and Intel format
p111: assembly code suffix for different data in tables
P112: These registers need to be understood in depth to know their usefulness. ESI EDI can be used to manipulate arrays, esp EBP is used to manipulate stack frames. For registers, especially eax,ebx,ecx,edx in the general register, it is understood that the ah,al of the ax,8 bits of the 32-bit eax,16 bits are independent, as shown in the following example:
假定当前是32位x86机器,eax寄存器的值为0x8226,执行完addw $0x8266, %ax指令后eax的值是多少? 解析:0x8226+0x826=0x1044c, ax是16位寄存器,出现溢出,最高位的1会丢掉,剩下0x44c,不要以为eax是32位的不会发生溢出.
P113: The combination of tables, in-depth understanding of the various addressing methods; Understand the three types of operands: immediate count, register, memory;
Master the calculation method of valid address Imm (eb,ei,s) = Imm + R[eb] + r[ei]*s
P114:mov equivalent to the assignment "=" of the C language, paying attention to the direction in the ATT format,
Also note that you cannot direct MOV from the memory address to another memory address, to use the register to relay a bit. Can distinguish Mov,movs,movz, master Push,pop
p115/p116: Stack frame and push pop; Note that the address of the top element of the stack is the lowest of all the element addresses in the stack.
p117: The pointer is the address, and the local variable is stored in the register.
p119: To understand the arithmetic and logic operations in conjunction with the table, note the purpose of the operand is what type of special attention to subtraction is who minus who pay attention to shift operation shift amount can be the number of immediate or%CL
P123: The C language to understand the control section, that is, the branch (If/switch), the Loop statement (while, for) how to implement. Test everyone extrapolate learning ability. The core of the control is the jump statement: Conditional jump p128 (Implementation if,switch,while,for), unconditional jump to jmp (to achieve goto)
P124: Conditional jump condition See status register (textbook is called Conditional Code Register) Note Leal do not change the condition code register think about it: Where are CMP and sub used P125:set directives to set conditional codes based on t=a-b results
p127: Jump and label
Assembly structure of the P130/p131:if-else
P132/p133:do-while
P134/p135:while
P137/p138:for
P144/p145:switch
The P149:IA32 implements the procedure call through the stack. Master the stack frame structure and pay attention to the stacking order of function parameters.
P150/p151:call/ret; function return value exists in%eax
P174:bt/frame/up/down: gdb command on stack frames
Second, the experimental exercise
- (The following command is available for lab building 64-bit Linux virtual machine environments, 32-bit Linux environments may be slightly different) using
gcc –S –o main.s main.c -m32
The commands are compiled into assembly code, and the numbers and function names in the following code should be modified to avoid being identical to others.
int g(int x){ return x + 3;}int f(int x){ return g(x);}int main(void){ return f(8) + 1;}
Remove the GCC generation code with "." The beginning of the compiler directive, the case for each instruction to draw the corresponding stack frame
(optional) Dynamic view of the call stack frame using GDB's Bt/frame/up/down instruction
Machine-level representation of the program