CSAPP
references:
- http://www.cs.cmu.edu/afs/cs/academic/class/15213-f15/www/schedule.html
- https://www.bilibili.com/video/BV1iW411d7hd
- https://www.bilibili.com/video/BV19X4y1P7zW?p=1
16进制2进制对照表
DEC | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
HEX | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
BIN | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
DEC | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|---|---|---|
HEX | 8 | 9 | A | B | C | D | E | F |
BIN | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Machine-Level Representation of Programs
3.3 Data Formats 数据格式
Intel uses the term “word” to refer to a 16-bit data type .
- 1 word = 16bit
- double words = 32bit
- quad words = 64bit
Size of C data types in x86-64
C decalaration | Intel data type | Assembly-code suffix | Size(bytes) |
---|---|---|---|
char | byte | b | 1 |
short | word | w | 2 |
int | double word | l | 4 |
long | quad word | q | 8 |
char * | quad word | q | 8 |
float | single precision | s | 4 |
double | double precision | l | 8 |
3.4 Acssessing Information
- low-order bytes 低位字节
访问寄存器从低位到高位因为操作数的大小,能访问的bit数也不同。
64 register | 意思 | 备注 |
---|---|---|
%rax | return value | |
%rbx | callee saved | |
%rcx | 4th argument | |
%rdx | 3rd argument | |
%rsi | 2nd argument | |
%rdi | 1nd argument | |
%rbp | callee saved | |
%rsp | stack point | |
%r8 | 5th argument | |
%r9 | 6th argument | |
%r10 | callee saved | |
%r11 | callee saved | |
%r12 | callee saved | |
%r13 | callee saved | |
%r14 | callee saved | |
%r15 | callee saved |
3.5 Arithmetic and Logical Operations
3.5.1 Load Effective Address
3.6 Control
3.6.1 Condition Codes
-
CF: Carry flag. The most recent operation generated a carry out of the most significant bit. Used to detect overflow for unsigned operations.
-
ZF: Zero flag. The most recent operation yielded zero.
-
SF: Sign flag. The most recent operation yielded a negative value.
-
OF: Overflow flag. The most recent operation caused a two’s-complement overflow—either negative or positive.
3.6.4 Jump Instruction Encodings
For the most part, we will not concern ourselves with the detailed format of machine code.
在极大程度上,我们不关心机器代码格式细节。
On the other hand, understanding how the targets of jump instructions are encoded will become important when we study linking in Chapter 7.
理解跳转对学习第七章的链接非常重要。
In addition, it helps when interpreting the output of a disassembler.
此外,他能帮助理解反汇编器的解释执行输出。
In assembly code, jump targets are written using symbolic labels.
在汇编代码中,跳转目标用符号标号书写。
The assembler, and later the linker, generate the proper encodings of the jump targets.
汇编器,和后边的连接器,会产生跳转目标适当的代码。
There are several different encodings for jumps, but some of the most commonly used ones are PC relative.
跳转目标有几种不同的编码,但是常用的都是PC相对的。
PC = program counter
程序计数器
That is, they encode the difference between the address of the target instruction and the address of the instruction immediately following the jump.
用地址差做目标跳转。
These offsets can be encoded using 1, 2, or 4 bytes.
偏移量可以编码为1、2、4 byte
A second encoding method is to give an “absolute” address, using 4 bytes to directly specify the target.
第二种方法就是给一个“绝对”地址,用4个字节。
The assembler and linker select the appropriate encodings of the jump destinations.
汇编器和连接器会选择合适的跳转编码。