close

最近在複習計算機組織,看到一個不錯的網頁(附在reference)

邊看邊做個筆記~

 

Instruction Set Architecture (ISA) 在設計時所需考慮的議題:

1. 暫存器 (registers)

- 需要用到多少暫存器? (每個 instruction 中需留一些 bits 來記錄 register number)

- 特殊暫存器的存取權 (ex: Program Counter(PC))

 

2. Bus size

- data bus size 要多大? (ISA word 大小要多大?)

- address bus size 要多大? (決定了 CPU 可以存取多少 memory, 也影響了單一個 instruction 的大小)

 

3. Operation

-  要多少個 operation? (instruction 中需保留 bits 來記錄 operation)

- 優缺點:

多: programmer 比較方便, 但實作麻煩, 且須保留較多 bits

少: programmer 較不方便, 但實作簡易, 需保留的 bits 較少

 

4. 運算元 (operand) 數量

- 每個 operation 需要幾個operand

- ex:

3-operand instruction: ADD R1, R2, R3 (R1=R2+R3)

2-operand instruction: LOAD R3, 4000 (從memory位置為4000的地方取值再存入R3)

1-operand instruction: INCR R4 (R4++)

 

5. literal values

- 在每個 instruction 中有地方可以讓我們放 literal value 嗎?

有 => 沒用到的時候空間就被浪費掉了

沒有 => 每次有 literal value 的時候都一定要先存在某個暫存器內不然就要去 memory 找

 

6. instruction format

- 要單一種 format 還是多種?

 

7. Decision Making (if / loop/ function call)

- status register (ex: zero flag, negative flag): 我們可以將原本"比較"的 operation 改成 subtraction 再設 flag

 

 

CISC: Complex Instruction Set Computing

- 那個年代由於 transistor 數量限制因此傾向設計使用較少暫存器的ISA,也因此有較多的memory access

- 為了要配合不同功能的 instruction,instruction 長度不太固定

- 有許多不同的 addressing mode

- Ex: Intel IA-32

 

RISC: Reduced Instruction Set Computing

- 減少了 CPU 需要直接存取主記憶體的頻率

- simple addressing mode

- pipeline 的概念被引進

- 統一的 instruction format (長度只有一個 word)

- 硬體上的 data type 較 CISC 少

- 適合用於嵌入式裝置(ex: 手機)

- Ex: ARM

 

 

MIPS ISA

- 經典 RISC 代表

- data bus size (and the word size): 32 bits  

- address bus size: 32 bits

- 4 種 integer data type: 8-bit bytes, 16-bit halfwords, 32-bit words, 64-bit doublewords

- 浮點數: single-precision: 32-bit; double-precision: 34-bit

- 提供 32 個 general-purpose 32-bit 暫存器

- 3 種 instruction format: R-type, I-type, J-type

- special-purpose register:

HI, LO 用來存乘除法的結果

$epc: 用來處理 interrupts 和 exceptions

 

1. R-type instruction

- 負責算術與邏輯

- 3 operands

- Format:

op: operation

rs: operand1暫存器

rt: operand2暫存器

rd: 目標暫存器

shamt: shift amount

func: function

- Ex:

 

2. I-type instructions

- 負責 load/store 和 immediate literal values

- 3 operands

- Format

op: operation

rs: operand1

rt: operand2

address/immediate: operand3, 可能是一個 16-bit 的 literal value 或是 32-bit 的 address

-pseudo-instruction:

ex: lw $1, 0x12345678 (load 32-bit literal value 0x12345678 into register $1)

但 immediate 欄位只有16 bits

因此 assembler 會將其變成 2 個 instructions: lui (load upper immediate), ori (OR immediate)

-branches: PC change是相對的(比較: jump 的 PC change 是絕對的)

ex: 

注意: immediate value 會乘以 4 (因為一個 instruction 長度為 4 bytes)

 

3. J-type instructions

- 負責 jump 和 function calls

- Format:

注意: target address 會再乘以 4 後再存到 $PC

 

 

 

reference:

https://minnie.tuhs.org/CompArch/Lectures/week02.html

arrow
arrow

    慈 發表在 痞客邦 留言(0) 人氣()