Question: computer organization Study the code to understand the array memory arrangement and loop operation using beq and j assembly instructions. Now, modify the program to

computer organization

  1. Study the code to understand the array memory arrangement and loop operation using beq and j assembly instructions.

  1. Now, modify the program to declare another integer type of array called array2:

array2: .space 32 #size of the array (8) x word size (4) = 32 bytes

  1. Modify the code to copy the contents of the array to array2.
  2. Modify the code to display the contents of array2
  3. Assemble and execute the code and also observe the output.
  4. Modify the code to add all elements in array and display the result.
  5. Assemble and execute the code and also observe the output.
  6. Submit the Lab05.asm file on Canvas.

the code is below:

.data array: .word 10, 11, 12, 13, 14, 15, 16, 17 # int array[8] = {10, 11, 12, 13, 14, 15, 16, 17}; size: .word 8 # size of the array = 8 comma: .asciiz ", " # Comma seperator for display ################################################################################################### # We will use a loop to access all the array elements one at a time and display that to the screen. # ARRAY_SIZE = 8; # int i = 0; # while( # int i = 0; ; i++){ # printf("%d",array[i]); # } ################################################################################################### .text la $t0, array #load the starting address of the array to the register $t0 #set the loop control variables lw $t1, size #load the size of the array to the register $t1 li $t2, 0 #set $t2 to 0. It will be used as the loop counter/control variable #start of the loop LOOP: lw $t3, 0($t0) #load the array element at the address stored in $t0 to $t3 li $v0, 1 #load command to display an integer to $v0 add $a0, $zero, $t3 #load the array value to be displayed to $a0 from $t3 syscall #make the system call to display the array element li $v0, 4 #load command to display a string or character to $v0 la $a0, comma #load the comma seperator character to $a0 syscall #make the system call to display the comma seperator between the array elements addi $t2, $t2, 1 #increment the loop counter beq $t1, $t2, DONE #verify whether the loop counter value is equal to array size #since we started the loop counter value from 0, so when loop counter #becomes equal to the size of the array that means we are done #scanning through the entire array. If this is true then go to the label DONE. #else increment the array address pointer to the next element. addi $t0, $t0, 4 #increment the array address pointer to the next element. j LOOP #jump back to the label LOOP, which is the start of the loop. #Loop ends DONE:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!