<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Blog Title</title><link>https://flippyside.github.io/akosus.github.io</link><description>Blog description</description><copyright>Blog Title</copyright><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><image><url>https://github.githubassets.com/favicons/favicon.svg</url><title>avatar</title><link>https://flippyside.github.io/akosus.github.io</link></image><lastBuildDate>Tue, 01 Oct 2024 07:18:51 +0000</lastBuildDate><managingEditor>Blog Title</managingEditor><ttl>60</ttl><webMaster>Blog Title</webMaster><item><title>machine-level-programming[CSAPP]</title><link>https://flippyside.github.io/akosus.github.io/post/machine-level-programming%5BCSAPP%5D.html</link><description># basic&#13;
&#13;
## history of intel processors and architectures&#13;
&#13;
Intel X86 Processors：&#13;
&#13;
- dominate laptop/desktop/server market&#13;
- CISC(complex instruction set computer)&#13;
- evolution&#13;
  - 8086: 16-bit&#13;
  - 386(i386)(80386)(IA32) 32-bit&#13;
  - pentium4E(x86-64): 64-bit&#13;
  - core 2: multi-core&#13;
  - core i7: four cores&#13;
&#13;
Architecture(ISA: instruction set architecture): the parts of a processor design that needs to understand or write assembly/machine code&#13;
&#13;
machine code: byte-level programs, can be executed by processor&#13;
assembly code: a text representation of machine code&#13;
&#13;
programmer-visible state:&#13;
&#13;
- PC: program counter&#13;
  - address of next instruction&#13;
  - RIP in x86-64&#13;
- Register File: heavily used program data&#13;
- Condition Codes:&#13;
  - store status information about most&#13;
  - used for conditional branching&#13;
- Memory&#13;
  - byte addressable array&#13;
  - code and user data&#13;
  - stack to support procedures&#13;
&#13;
```c&#13;
long plus(long x, long y);&#13;
void sumstore(long x, long y, long *dest){&#13;
    long t = plus(x, y);&#13;
    *dest = t;&#13;
}&#13;
```&#13;
&#13;
```asm&#13;
sumstore:&#13;
  pushq %rbx&#13;
  movq %rdx, %rbx&#13;
  call plus&#13;
  movq %rax, (%rbx)&#13;
  popq %rbx&#13;
  ret&#13;
```&#13;
&#13;
## assembly characteristics&#13;
&#13;
Data type:&#13;
&#13;
- integer data of 1,2,4, 8 byte&#13;
- floating point data of 4, 8, 10 byte&#13;
- code: byte sequences encoding series of instructions&#13;
- no aggregate types such as arrays or structures&#13;
&#13;
Operation:&#13;
&#13;
- perform arithmetic function on register or memory data&#13;
- transfer data between memory and register&#13;
- transfer control&#13;
&#13;
```&#13;
# C code&#13;
*dest = t;&#13;
&#13;
# Assembly&#13;
movq %rax, (%rbx) # move 8-byte value to memory&#13;
# operands:&#13;
#  t:     register %rax&#13;
#  dest:  register %rbx&#13;
#  *dest:  memory  M[%rbx]&#13;
&#13;
# object code&#13;
0x40059e: 48 89 03&#13;
# 3-byte instuction&#13;
# stored at address 0x40059e&#13;
```&#13;
&#13;
![Alt text](assets/ch3/image-1.png)&#13;
&#13;
```&#13;
%r: 64bit&#13;
%e: 32bit&#13;
```&#13;
&#13;
x8664将寄存器增加到%r，相比i386增加了一倍&#13;
&#13;
![Alt text](assets/ch3/image-2.png)&#13;
&#13;
寄存器的名字在很早之前反映了他们的特定功能，现在没有这种对应了。</description><guid isPermaLink="true">https://flippyside.github.io/akosus.github.io/post/machine-level-programming%5BCSAPP%5D.html</guid><pubDate>Tue, 01 Oct 2024 07:18:23 +0000</pubDate></item></channel></rss>