I need help on this problem. Thanks Assignment 5 ECE 3130 3) [10 marks] Write a
ID: 3680966 • Letter: I
Question
I need help on this problem.
Thanks
Assignment 5 ECE 3130 3) [10 marks] Write a subroutine called PRUNE to search an array called raw measurements that contains 16-bit unsigned integers and exclude the elements that are less than a given value called Min and the elements that are more than a given value called Max. Store the remaining measurements in an array called pruned measurements. The length of the array is variable and it ends with $FFFF. Example: if raw measurements (255, 600, 9000, 0, 1700, 432, 8765, 50, $FFFF), Max 500, and Min 60, pruned measurements 1255, 432, $FFFF). The starting address of raw measurements and pruned measurements are passed by registers x and Y, respectively. Max and Min are two memory locations.Explanation / Answer
! Assembly language function to prune elements in an array A.
!
! Input: The address of the first data item of raw_measurements is given in %i0
! The number of data items in array raw_measurements is given in %i1
!The address of the first data item of prune_measurements is given in %i2
!
! Variables: Register %L0 is used as an array index. It counts 0 to n-1.
! Register %L1 is used to compute the address of raw_measurements[i].
! Register %L2 is used to load a data item from memory.
! Register %L4 is used to compute the address of prune_measurements[i].
! Register %L3 is used as an array index. It counts 0 to n-1.
! Register %L5 is used to compute the address of max.
! Register %L6 is used to compute the address of min.
! Register %L7 is used to load a data item from memory location of min.
! Register %L8 is used to load a data item from memory location of max.
!
.align 8
.skip 16
.global asum
asum:
!
! Create a new activation record with the save instruction.
!
save %sp,-112,%sp
!
! Initialize a counter1(raw_measurements) to zero. Also initialize the counter2(prune_measurements) to zero.
!
mov %g0, %L0
mov %g0, %L3
!
! Use a label to define the entry point of a loop. I.e., while (i<n) ...
!
Loop:
cmp %L0, %i1
bge OutOfLoop
nop
!
! Compute the address of A[i]
!
smul %L0,4,%L1
add %i0, %L1, %L1
! Load the value from memory
!
ld [%L1], %L2
ld [%L5], %L7
ld [%L6], %L8
cmp %L2, %L8
jle prune
cmp %L2, %L7
jge prune
!
! Add one to our counter
!
add %L0, 1, %L0
ba Loop
nop
!
!
prune:
!
! Compute the address of prune_measurements[i]
!
smul %L3,4,%L4
mov [%L3],%L2
add %i2, %L4, %L4
!
OutOfLoop:
!
! Move our pruned_measurements into our input register %i2 to return to the caller.
!
mov %L4, %i2
!
! Return
!
jmp %i7+8
restore
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.