CSAPP
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.