# Lab5
Name: T.Venkat Kaushal
Roll number: CS22B058
## Question 1
### Assembly code without Unrolling
```assembly=
.data
.word 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
.text
lui x1 0x10000
addi x1 x1 0x000
#s = x2
addi x2 x0 3
#i = x3
addi x3 x0 9
Loop:
blt x3 x0 end_loop
slli x4 x3 2
add x5 x4 x1
lw x6 0(x5)
add x6 x6 x2
addi x3 x3 -1
sw x6 0(x5)
j Loop
end_loop:
li a7 10
ecall
```
### Observations

1. We found that Cycles it took are 136
2. The IPC Count is: 0.699
### Assembly code with Unrolling 0f 4
```assembly=
.data
.word 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
.text
lui x1 0x10000
addi x1 x1 0x000
#s = x2
addi x2 x0 3
#i = x3
addi x3 x0 10
Loop:
blt x3 x0 end_loop
lw x4 0(x1)
lw x5 4(x1)
lw x6 8(x1)
lw x7 12(x1)
addi x4 x4 3
addi x5 x5 3
addi x6 x6 3
addi x7 x7 3
sw x4 0(x1)
sw x5 4(x1)
sw x6 8(x1)
sw x7 12(x1)
addi x3 x3 -4
addi x1 x1 16
j Loop
end_loop:
li a7 10
ecall
```
### Observations

1. We found that Cycles it took are 72
2. The IPC Count is: 0.764
### Assembly code with Unrolling 0f 2
```assembly=
.data
.word 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
.text
lui x1 0x10000
addi x1 x1 0x000
#s = x2
addi x2 x0 3
#i = x3
addi x3 x0 10
Loop:
blt x3 x0 end_loop
lw x4 0(x1)
lw x5 4(x1)
addi x4 x4 3
addi x5 x5 3
sw x4 0(x1)
sw x5 4(x1)
addi x3 x3 -2
addi x1 x1 8
j Loop
end_loop:
li a7 10
ecall
```
### Observations

1. We found that Cycles it took are 93
2. The IPC Count is: 0.72
## Question2
### Linked List - Reverse
```assembly=
.data
node1: .word 1
.word 0
node2: .word 2
.word 0
node3: .word 3
.word 0
node4: .word 4
.word 0
node5: .word 5
.word 0
node6: .word 6
.word 0
node7: .word 7
.word 0
node8: .word 8
.word 0
node9: .word 9
.word 0
node10: .word 10
.word 0
.text
la x1 node1
la x2 node2
la x3 node3
la x4 node4
la x5 node5
la x6 node6
la x7 node7
la x8 node8
la x9 node9
la x10 node10
sw x2 4(x1)
sw x3 4(x2)
sw x4 4(x3)
sw x5 4(x4)
sw x6 4(x5)
sw x7 4(x6)
sw x8 4(x7)
sw x9 4(x8)
sw x10 4(x9)
#end of initialization of linked list
mv x11 x1 #curr
mv x12 x0 #prev
mv x13 x0 #next
loop:
beq x11 x0 end_loop
lw x14 4(x11)
addi x13 x14 0
sw x12 4(x11)
mv x12 x11
mv x11 x13
j loop
end_loop:
li a7 10
ecall
```
## Observations
### Before Reversal of Linked List

### After Reversal of Linked List

### Question 3
```assembly =
.data
.word 1
.text
lui x1 0x10000
addi x1 x1 0x000
addi x3 x0 1 #value of the node
li x2 8 # indicates the size of the node
sw x3 0(x1) #store the value in the node
li x4 0
sw x4 4(x1) #updates the next pointer to null
mv a0, x1 #store the address of address of the a1 into a0 and returns.
ret #returning.
```
----------------