---
# System prepended metadata

title: LAB-5

---

# LAB-5 
##V_Pavan
##CS22B048

# Question-1
```assembly=
.data
array: .word 1 2 3 4 5 6 7 8 9 10 11 
.text

la x6 array  # first value address

addi x11 x0 11 # size of array

addi x6 x6 44  # last element

addi x28 x0 0
addi x1 x0 3 # s=3

loop:
 beq x1 x28 break   # unrolling by factor 4
 
 lw x5 0(x6)
 add x2 x5 x1
 sw x2 0(x6)
 addi x6 x6 -4
 
 lw x5 0(x6)
 add x2 x5 x1
 sw x2 0(x6)
 addi x6 x6 -4
 
 lw x5 0(x6)
 add x2 x5 x1
 sw x2 0(x6)
 addi x6 x6 -4

 lw x5 0(x6)
 add x2 x5 x1
 sw x2 0(x6)
 addi x6 x6 -4

 addi x22 x22 4
 addi x28 x28 1
j loop

break: 
li a7 10




.data
arr: .word 1,2,3,4,5,6,7,8,9,10,11  # with loop 
.text

la x1 arr
la x4 arr
addi x2 x0 12 #n
addi x3 x0 3
addi x5 x0 12

loop:
    beq x2 x0 exit
    addi x4 x0 4
    addi x2 x2 -1
    j loop
    
exit:
    beq x5 x0 exit1
    addi x5 x5 -1
    lw x20 0(x4)
    add x4 x4 x3
    addi x4 x4 -4
    j exit
    
    
    
exit1:
    li a7 4
    


```
this ipc with loop by 5 stage processor
![withoutunwrapping](https://hackmd.io/_uploads/r1IPjRnhT.png)
![Screenshot 2024-02-28 214517](https://hackmd.io/_uploads/rkuw3A33p.png)





This above one  ipc with unrolling loop by a factor 4


observation: the ipc value is increased in unrolling loop by factor 4,, 
 # Question-2
```assembly=
  .data
node1: .word 10
   .word 0
node2: .word 9
   .word 0
node3: .word 8
   .word 0
node4: .word 7
   .word 0
node5: .word 6
   .word 0
node6: .word 5
   .word 0
node7: .word 4
  .word 0
node8: .word 3
  .word 0
node9: .word 2
  .word 0
node10: .word 1
 .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)  # In the linkedlist the second node address    
sw x3 4(x2)  # stored in first ,like for all nodes 
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)
sw x0 4(x10) # here the last node contain null address


sw x9 0(x10)  # here i am reversing the address.,head to tail 
sw x8 0(x9)   # tail to head,,now the x1 contain null  
sw x7 0(x8)   # the x10 contain the x9 address 
sw x6 0(x7)
sw x5 0(x6)
sw x4 0(x5)
sw x3 0(x4)
sw x2 0(x3)
sw x1 0(x2)
sw x0 0(x1)  
```
![Screenshot 2024-02-28 005615](https://hackmd.io/_uploads/rk6tPhs26.png)


# Question-3

```
assembly=
.data
head: .word 1
      .word 0
middle: .word 2
        .word 0      
middle2: .word 3
      .word 0
tail: .word 4
      .word 0      
.text
j main

newnode:
        la x9 head
        addi x9 x9 4
        loop:
            lw x25 0(x9)
            addi x9 x9 8
            bne x25 x0 loop
        addi x9 x9 -8
        la x23 tail
        sw x23 0(x9)
       jalr x0 x7 0 
main:
     la x1 head
     la x2 middle 
     
     sw x2 4(x1)
     
     la x3 middle2
 
      sw x3  4(x2)
     sw  x0 4(x3)
 
    jal x7 newnode
    li a7 10 
    
```
![Screenshot 2024-02-28 004637](https://hackmd.io/_uploads/ByMAr3ihp.png)