---
# System prepended metadata

title: 106期中-解析
tags: [test, computer organization, thu]

---

###### tags: `computer organization` `test` `thu`
{%hackmd theme-dark %}
# 106期中-解析

## 1. Alternative compiled code sequences using instructions in classes A, B, C and D in the following table. Please identify which code sequence will get smaller average CPI than the other?

| Class             | A | B | C | D |
| ----------------- | - | - | - | - |
| CPI for class     | 1 | 2 | 3 | 4 |
| IC in sequence 1  | 2 | 5 | 4 | 5 |
| IC in sequence 2  | 4 | 3 | 3 | 4 |
### Solution: 
- IC in sequence 1：$$\frac{1\cdot2+2\cdot5+3\cdot4+4\cdot5}{2+5+4+5}=3.38$$

- IC in sequence 2：$$\frac{1\cdot4+2\cdot3+3\cdot3+4\cdot4}{2+5+4+5}=2.5$$

$\Longrightarrow$ sequence 2有較小的平均CPI。

## 2. Consider two different implementations, M1 and M2, of the same instruction set. There are three classes of instructions (A, B and C) in the instruction set. M1 has a clock rate of 80 MHz and M2 has a clock rate of 100 MHz. The average number of cycles for each instruction class and their frequencies (for a typical program) are as follow:

|Instruction Class|Machine M1 - Cycles/Instruction Class | Machine M2 - Cycles/Instruction Class | Frequency |
|:----------------|:---------|:----------|:---------|
|A                |1        |2        |60%            |
|B                | 2        |3            |30%        |
|C                | 4        |4            |10%        |

### (a) Calculate the average CPI for each, M1, and M2.

- M1：$$1\cdot 0.6+2\cdot 0.3+4\cdot 0.1=1.6$$
- M2：$$2\cdot 0.6+3\cdot 0.3+4\cdot 0.1=2.5$$

### (b) Calculate the average MIPS rating for each, M1, and M2.

- M1：$$\frac{80\cdot 10^6}{1.6\cdot 10^6}=50$$

- M2：$$\frac{100\cdot 10^6}{2.5\cdot 10^6}=40$$

## 3. 此為題組
### a. 請用圖示說明MIPS的定址法(Addressing): Register Addressing、Base Addressing、PC-Relative Addressing 及Pseudo direct Addressing。(搭配MIPS R-I-J指令格式解釋)

- MIPS addressing mode

    ![](https://i.imgur.com/2x13H1B.gif)

### b. 說明Base Addressing, PC-Relative Addressing的差異。
-  Base Addressing和PC-Relative Addressing的差異在於Base  Addressing 在計算位址時是暫存器加上指令常數。
-  PC-Relative Addressing 在計算位址時則是PC加上指令常數。

### c. 為何Immediate Addressing最有效率？
- immediate Addressing最有效率的原因是不需要去找位址。

## 4. If branch target is too far to encode with 16-bits offest(I format), 請舉例如何解決。


當要跳過去的目標位置太遠無法用 16 bit 表達
可以改寫指令使存放 address 的 bit 更大
e.g. j and jal 有 26 bits

### Example
```MIPS=
beq $s0, $s1, L1 # 16 bits
bne $s0, $s1, L2 # 16 bits
j L1             # 26 bits
L2: ...po
```
## 5. We have a processor with the following components (next page), please draw the data path on those components (Gray part) for add and lw instructions, respectively (個別地).
![](https://i.imgur.com/ux0mDln.png)

### A. `add rd, rs, rt`
![](https://i.imgur.com/tZympHH.png)

### B. `lw rt, offest(rs)`
![](https://i.imgur.com/IKsrxjA.png)


## 6. Please calculate the number of FPU of Top1, Top3 and Top5 Supercomputers respectively.
### $$R_{max} = Cores \cdot CPU\ Frequency \cdot FPU$$
![](https://i.imgur.com/eGNdwPg.png)
- Top 1： 
$$93014.6 = 10649600\cdot 1.45\cdot FPU$$
$$FPU = 0.006$$

- Top 3: 
$$19590.0=361760\cdot 2.6\cdot FPU$$
$$FPU=0.2$$

- Top 5： 
$$17590.0=560640\cdot 2.200\cdot FPU$$
$$FPU=0.014$$



