---
# System prepended metadata

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

---

###### tags: `computer organization` `test` `thu`
{%hackmd theme-dark %}
# 107期中-解析
## 1. Please calculate the number of FPU of Top2 and Top8 Supercomputers respectively.
### Note
- FPU should be an integer.
- Core's frequency is GHz, so use $Gflops$ for calculation.
- $$1000\ Gflops = 1\ Tflops$$
- $$R_{peak}=Cores \times Core's\ Frequency \times FPU$$
![](https://i.imgur.com/4mQPfYH.png)
#### Solution
- Rank 1 (Top 2):
$$125,435.9 \cdot 1000 = (10,649,600) \cdot (1.45) \cdot FPU$$
$$125,435,900 = (154,419,20)\cdot FPU$$
$$FPU \approx 8.12 \approx 8$$

- Rank 2 (Top 8):
$$20,132.7 \cdot 1000 = (1,572,864) \cdot (1.6) \cdot FPU$$
$$20,132,700 = (2,516,582.4) \cdot FPU$$
$$FPU \approx 8$$

## 2. 請說明`jr`與`jal`的用途與差異。
jr指令為使用暫存器的跳躍指令，跳躍位址在暫存器中，用於switch和程序返回

jal指令為帶有連結功能的直接跳躍指令，指令的跳躍地址在指令中，跳躍發生時把返回地址存放到R31暫存器中，用於程序呼叫。

## 3. MIPS因為沒有暫存器搬移指令，請說明如何逹到暫存器搬移功能。請使用`move $t2, $t1`作為例子。
`move $t2, $t1` 轉成mips指令 = `add $s1,$0,$t1`

## 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

## 5. 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 machine, M1 and M2.

- M1：$$1\cdot0.6+2\cdot0.3+4\cdot0.1=1.6$$
- M2：$$2\cdot0.6+3\cdot0.3+4\cdot0.1=2.5$$

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

- M1：$$\frac{80\cdot 10^6}{1.6\cdot 10^6}$$
- M2：$$\frac{100\cdot 10^6}{2.5\cdot 10^6}$$


## 6.(題組)
### 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最有效率的原因是不需要去找位址。

## 7. Please fill the blank each:
![](https://i.imgur.com/FF0zadl.png)
| op | rs | rt | imm|
| --- | -- | - | - |
| 43 | 9  | 19 | 0 |

參: https://www.d.umn.edu/~gshute/mips/itype.xhtml#function-codes
及: ![](https://i.imgur.com/qftfftd.png)



## 8. Please list all components for constructing a MIPS processor.
- ALU
- Registers
- Data memory
- Mux
- Sign-extend

## 9.  We have a processor with the following components (next page), please draw the data path on those components (Gray part) for add and sw instructions, respectively (個別地).
![](https://i.imgur.com/ux0mDln.png)

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


### B. `sw rs, offset(rt)`
![](https://i.imgur.com/MmpC12t.png)







