---
# System prepended metadata

title: CA HW1

---

# CA HW1
B08902093 石諾盟

## Question 1
a.
Formula,
CPI = CPU time / (IC * Clock cycle time)
1. CPI_A = $1.1$ , CPI_B = $1.25$

b.
Formula,
Clock rate_A = 1.1 * 1E-9 /(CPU time)
Clock rate_B = 1.25 * 1.2E-9 / (CPU time)
1. Clock rate_A = 0.73 * Clock rate_B, hence A is 27% slower or B is 36% faster.

c. 

time_C = $(6 * 10^8)*(1.1) *(1*10^{-9})$
Speedup_vs_A = $1.67$
Speedup_vs_B = $2.27$
## Question 2
total = 250ns, FP = 70ns, L/S = 85ns, B = 40ns, INT = 55ns 
1. ans $= 55 + 40 + 85 + 70 * 0.8 = 236$ns -> reduced by 5.6%
2. ans $= 250 * 0.8 - 85 - 40 - 70 - x = 5$ns -> reduced by 91% 
3. ans = No. since 250 - 40 is greater than 200 and branching operations do not take over 40s.
## Question 3
x5 = 0x00000000AAAAAAAA
x5 << 4 = 0x0000000AAAAAAAA0
x5 >> 3 = 0x0000000015555555
x6 = 0x1234567812345678
x6 << 6 = 0x12345678123456780

1. ans = 0x1234567ABABEFEF8 
2. ans = 0x2345678123456780
3. ans = 0x0000000000000545

## Question 4
```clike=
int result = 0;
for (int i = 0; i < 100; i++) {
    result += MemArray[0]
    MemArray++
}
```

## Question 5
Idea
```clike=
int sum(int MemArray[], int N) {
    /* in this case N is 99. */
    if (N <= 0)
        return 0;
    return sum(MemArray, N - 1) + MemArray[N-1]   
}
```
```
addi x29, x0, 800-8 // 8 * 100 since it's risc V convention and 792 -> 99
LOOP: 
    ld x7 x29(x10)
    add x5, x5, x7
    addi x29, x29, -8 // Decrement by 1
    bge x29, x0, LOOP

```