# Lab 5
Name: M V Sonith
Roll No.: CS22B036
---
# Question 1
**Code with out unrolling:**
```assembly=
.data
array: .word 1 2 3 4 5 6 7 8 9 10 11
base: .word 0x10000000
.text
addi x20 x0 3
lw x24 base
addi x26 x24 -4
lw x21 base
addi x21 x21 40
addi x22 x0 0
loop:
beq x21 x26 exit
lw x25 0(x21)
add x25 x25 x20
sw x25 0(x21)
addi x21 x21 -4
j loop
exit:
li a7 10
ecall
```
**observation**

**Code with unrolling:**
```assembly=
.data
array: .word 1 2 3 4 5 6 7 8 9 10 11
base: .word 0x10000000
.text
addi x20 x0 3
lw x24 base
addi x26 x24 -8
lw x21 base
addi x21 x21 40
addi x22 x0 0
loop:
beq x21 x26 exit
lw x25 0(x21)
add x25 x25 x20
sw x25 0(x21)
lw x25 -4(x21)
add x25 x25 x20
sw x25 -4(x21)
lw x25 -8(x21)
add x25 x25 x20
sw x25 -8(x21)
lw x25 -12(x21)
add x25 x25 x20
sw x25 -12(x21)
addi x21 x21 -16
j loop
exit:
li a7 10
ecall
```
**observation**

---
# Question2
**Code:**
```assembly=
.data
node1: .word 0 # value
.word 0 # pointer to next node
node2: .word 0
.word 0
node3: .word 0
.word 0
node4: .word 0
.word 0
node5: .word 0
.word 0
node6: .word 0
.word 0
node7: .word 0
.word 0
node8: .word 0
.word 0
node9: .word 0
.word 0
node10: .word 0
.word 0
.text
# link the nodes
la x20 , node1
la x21 , node2
la x22 , node3
la x23 , node4
la x24 , node5
la x25 , node6
la x26 , node7
la x27 , node8
la x28 , node9
la x29 , node10
addi x4 x0 1
sw x4 , 0(x20)
sw x21 , 4( x20 )
addi x4 x4 1
sw x4 , 0(x21)
sw x22 , 4( x21 )
addi x4 x4 1
sw x4 , 0(x22)
sw x23 , 4( x22 )
addi x4 x4 1
sw x4 , 0(x23)
sw x24 , 4( x23 )
addi x4 x4 1
sw x4 , 0(x24)
sw x25 , 4( x24 )
addi x4 x4 1
sw x4 , 0(x25)
sw x26 , 4( x25 )
addi x4 x4 1
sw x4 , 0(x26)
sw x27 , 4( x26 )
addi x4 x4 1
sw x4 , 0(x27)
sw x28 , 4( x27 )
addi x4 x4 1
sw x4 , 0(x28)
sw x29 , 4( x28 )
addi x4 x4 1
sw x4 , 0(x29)
addi x15 x0 0 #previous pointer
la x16 node1 #current pointer
lw x18 4(x16) #next pointer
loop:
beq x16 x0 exit #if current ==NULL end loop
sw x15 4(x16) #cur->nxt = pre
addi x15 x16 0 #pre = cur
addi x16 x18 0 #cur = nxt
lw x18 4(x18) #nxt = nxt ->next
j loop
exit:
addi x10 x15 0 # address of new Head node
li a7 10
ecall
```
**Output:**
**Before reversing list and and after intialiazation of linked list**

**After reversing Linked list**

---
# Question3
**Code:**
```assembly=
.data
node1: .word 0 # value
.word 0 # pointer to next node
node2: .word 0
.word 0
node3: .word 0
.word 0
node4: .word 0
.word 0
node5: .word 0
.word 0
node6: .word 0
.word 0
node7: .word 0
.word 0
node8: .word 0
.word 0
node9: .word 0
.word 0
node10: .word 0
.word 0
.text
# link the nodes
la x20 , node1
la x21 , node2
la x22 , node3
la x23 , node4
la x24 , node5
la x25 , node6
la x26 , node7
la x27 , node8
la x28 , node9
la x29 , node10
addi x4 x0 1
sw x4 , 0(x20)
sw x21 , 4( x20 )
addi x4 x4 1
sw x4 , 0(x21)
sw x22 , 4( x21 )
addi x4 x4 1
sw x4 , 0(x22)
sw x23 , 4( x22 )
addi x4 x4 1
sw x4 , 0(x23)
sw x24 , 4( x23 )
addi x4 x4 1
sw x4 , 0(x24)
sw x25 , 4( x24 )
addi x4 x4 1
sw x4 , 0(x25)
sw x26 , 4( x25 )
addi x4 x4 1
sw x4 , 0(x26)
sw x27 , 4( x26 )
addi x4 x4 1
sw x4 , 0(x27)
sw x28 , 4( x27 )
addi x4 x4 1
sw x4 , 0(x28)
sw x29 , 4( x28 )
addi x4 x4 1
sw x4 , 0(x29)
la x16 node1 #current pointer
loop:
lw x18 4(x16) # cur->nxt
beq x18 x0 add_node # checking curr->nxt ==NULL
add x16 x18 x0 # cur = cur->nxt;
j loop
add_node:
addi x19 x0 11
addi x9 x16 8 # allocating in address x16 +8
sw x19 0(x9) # new node val =11
sw x0 4(x9) # new node->nxt = NULL
sw x9 4(x16) # curr->nxt = new node
li a7 10
ecall
```
**Output:**
**Before adding new node**

**After adding new node**

---