# Lab 5 Name: SUDDULA VINEETH RAGHAVENDRA Roll No.: CS22B045 --- ## Question 1 **Code** (if required) ```assembly= .data array: .word 1 2 3 4 5 6 7 8 9 10 12 str: .string " " str1: .string "after updation of the array" str2: .string "\n" base: .word 0x10000000 .text la x21,array addi x21,x21,40 # we storing the last element address in the x21. la x22,array li x3,3 li x2,0 li x11,11 li x25,12 srli x26,x25,2 # here they mentioned factor of 4. li x9,11 li x5,0 loop: beq x2,x3,exit addi x2,x2,1 lw x10,0(x21) addi x10,x10,3 sw x10,0(x21) lw x10,-4(x21) addi x10,x10,3 sw x10,-4(x21) lw x10,-8(x21) addi x10,x10,3 sw x10,-8(x21) lw x10,-12(x21) addi x10,x10,3 sw x10,-12(x21) addi x21,x21,-16 j loop exit: li a0,10 ecall ``` **Observation:** The value of IPC is 0.724 when we do the loop unrolling with 4 factor. Without loop unrolling the value of IPC is 0.67. So it is a good optimization. --- ## Question 2 **Code** (if required) ```assembly= # reference code from lab example. .data node1: .word 10 #value .word 0 #pointer to next node node2: .word 20 .word 0 node3: .word 30 .word 0 node4: .word 40 .word 0 node5: .word 50 .word 0 node6: .word 60 .word 0 node7: .word 70 .word 0 node8: .word 80 .word 0 node9: .word 90 .word 0 node10:.word 100 .word 0 .text init: la x3,node1 la x4,node2 sw x4,4(x3) la x3,node3 sw x3,4(x4) la x4,node4 sw x4,4(x3) la x3,node5 sw x3,4(x4) la x4,node6 sw x4,4(x3) la x3,node7 sw x3,4(x4) la x4,node8 sw x4,4(x3) la x3,node9 sw x3,4(x4) la x4,node10 sw x4,4(x3) la x3,node1 reverse: #here we used three pointer approach to reverse the actual linked list which is used in DSA. li x4,0 mv x5,x3 mv x6,x3 loop: beq x5,x0,exit lw x6,4(x5) sw x4,4(x5) mv x4,x5 mv x5,x6 j loop exit: #By this step the total linked list will be reversed. li a7,10 ecall ``` **Observation:** Here we are initializing 10 nodes and here each word will be storing 4 bytes in memory. So at the end each node will be taking 8 bytes in the memory. --- ## Question 3 ```assembly= # reference code from lab .data node1: .word 10 #value .word 0 #pointer to next node node2: .word 20 .word 0 node3: .word 30 .word 0 node4: .word 40 .word 0 node5: .word 50 .word 0 node6: .word 60 .word 0 node7: .word 70 .word 0 node8: .word 80 .word 0 node9: .word 90 .word 0 node10:.word 100 .word 0 .text init: la x3,node1 la x4,node2 sw x4,4(x3) la x3,node3 sw x3,4(x4) la x4,node4 sw x4,4(x3) la x3,node5 sw x3,4(x4) la x4,node6 sw x4,4(x3) la x3,node7 sw x3,4(x4) la x4,node8 sw x4,4(x3) la x3,node9 sw x3,4(x4) la x4,node10 sw x4,4(x3) allocate_node: la x9,node1 li x10,0 join: beq x9,x0,allocate lw x10,4(x9) lw x9,4(x10) j join allocate: # here x10 is pointing towards the last node. mv x9,x10 addi x9,x9,8 sw x9,4(x10) li x9,110 # just we are creating a node with the value of 110. sw x9,8(x10) sw x0,12(x10) # after this step a new node will be allocated. ``` **Observation:** By this approach we will be able to create a node by allocating new memory. ---