Intro to CPU

roychuang

What is CPU

What is CPU

  • 中央處理器 (Central Processing Unit)
  • 整台電腦的大腦
  • 負責處理所有的計算/資源分配
  • 負責執行程式碼

What is CPU

How CPU Works

How CPU works

CPU Architecture

Assembly & Binary Executable

Assembly & Binary Executable

Compile

  • 組合語言 (Assembly)
  • 通常是編譯以後的產物 或者負責寫驅動程式的可能會手刻
  • 接近機械碼 但是是人類可以閱讀的 (?
  • 再經過組譯可以轉成機械碼

Assembly

Assembly & Binary Executable

C vs Assembly

// Simple Hello World program in C
#include<stdio.h>

int main()
{
    // printf() is a output function which prints
    // the passed string in the output console
    printf("Hello World!");
    
    return 0;
}
	.file	"hello.c"
	.def	___main;	.scl	2;	.type	32;	.endef
	.section .rdata,"dr"
LC0:
	.ascii "Hello World!\0"
	.text
	.globl	_main
	.def	_main;	.scl	2;	.type	32;	.endef
_main:
LFB12:
	.cfi_startproc
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset 5, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register 5
	andl	$-16, %esp
	subl	$16, %esp
	call	___main
	movl	$LC0, (%esp)
	call	_printf
	movl	$0, %eax
	leave
	.cfi_restore 5
	.cfi_def_cfa 4, 4
	ret
	.cfi_endproc
LFE12:
	.ident	"GCC: (MinGW.org GCC-6.3.0-1) 6.3.0"
	.def	_printf;	.scl	2;	.type	32;	.endef

Assembly & Binary Executable

想學記得去資安小社

Assembly & Binary Executable

Assemble

Assembly & Binary Executable

  • 組譯 (Assemble)
  • 把組合語言轉換成機械碼 (Executable)

Opcode

Assembly & Binary Executable

這應該是  x86

Logic Gates

Logic Gates

Turing Complete

  • 有人記得圖靈焦油坑嗎
  • 只要一個東西是圖靈完備,他就可以用來實現所有邏輯閘,以此實現所有的運算功能
  • CPU 是由各種用電路蓋成的邏輯閘所構成,以此來運行所有的運算
  • 沒錯,紅石電路也是種電路

Logic Gates

Logic Gates

Logic Gates

Adder

Logic Gates

CPU Circuit

Thanks

cpu-intro

By Roy Chuang

cpu-intro

  • 50