---
# System prepended metadata

title: 計算機結構期中筆記
tags: [109-2, NTNU, ArchitectuteComputers]

---

---
title: 計算機結構期中筆記
tags: 109-2,NTNU,ArchitectuteComputers
---
- Clock period 時脈週期：duration of a clock cycle
- Clock frequency (rate) 時脈頻率：cycles per second
- Clock cycles:
    $\text{Clock Cycles}=\sum_{i=1}^n\left(\text{CPI}_i\times\text{Instruction Count}_i\right)$
- CPU time
    $\begin{aligned}
\text{CPU time}&=
\text{CPU Clock Cycles}\times\text{Clock Cycle Time}
\\&=\frac{\text{CPU Clock Cycles}}{\text{Clock Rate}}
\end{aligned}$
- CPI
    $\text{CPI} = \frac{\text{Clock Cycles}}{\text{Instruction Count}} = \sum^n_{i=1}\left(\text{CPI}_i\frac{\text{Instruction Count}_i}{\text{Instruction Count}}\right)$
- Instruction Count
- Clock cycle Time
    $\begin{aligned}
    \text{Clock Cycles Time}=
    \frac{1}{\text{Clock Rate}}
    \end{aligned}$

| dec | binary | oct | hex |
| --- | ------ | --- | --- |
| 1   | 0001   | 001 | 1   |
| 2   | 0010   | 002 | 2   |
| 3   | 0011   | 003 | 3   |
| 4   | 0100   | 004 | 4   |
| 5   | 0101   | 005 | 5   |
| 6   | 0110   | 006 | 6   |
| 7   | 0111   | 007 | 7   |
| 8   | 1000   | 010 | 8   |
| 9   | 1001   | 011 | 9   |
| 10  | 1010   | 012 | A   |
| 11  | 1011   | 013 | B   |
| 12  | 1100   | 014 | C   |
| 13  | 1101   | 015 | D   |
| 14  | 1110   | 016 | E   |
| 15  | 1111   | 017 | F    |

```MIPS=
fib:    addi $sp, $sp, -12  #make room on stack
        sw   $ra, 8($sp)    #push $ra
        sw   $s0, 4($sp)    #push $s0 (local temporary variable)
        sw   $a0, 0($sp)    #push $a0 (argument)
        bne  $a0, $0, test1 #if n is not equal to 0, go to test1
        add $v0, $0, $0
        j exit
test1:  addi $t0, $0, 1     #$t0 = 1
        bne $a0, $t0, else2 #if n is not equal to 1, go to else2
        add $v0, $t0, $0
        j exit
else2:  addi $a0, $a0, -1   #$a0 = n - 1
        jal fib             #call fib(n - 1)
        add $s0, $v0, 0     #$s0 = fib(n - 1)
        addi $a0, $a0, -1   #$a0 = n - 2
        jal fib             #call fib(n - 2)
        add $v0, $v0, $s0   #$v0 = fib(n - 1) + fin(n - 2)
exit:   lw $a0, 0($sp)      #pop $a0
        lw $s0, 4($sp)      #pop $s0
        lw $ra, 8($sp)      #pop $ra
        addi $sp, $sp, 12   #restore $sp
        jr $ra              
```

```MIPS=
# B[8] = A[i-j]
sub $t0, $s3, $s4   #$t0 = i - j
sll $t0, $t0, 2     #$t0 = (i - j) * 4
add $t0, $s6, $t0   #$t0 = &A[i - j]
lw  $t0,  0($t0)    #$t1 = A[i- j]
sw  $t1, 32($s7)    #B[8] = $t1 = A[i - j]
```