Question: Write an MSP430 assembly language subroutine, REP_FREE, to examine the elements of a list of positive word-size numbers stored at location LIST_IN. The list is
Write an MSP430 assembly language subroutine, REP_FREE, to examine the elements of a list of positive word-size numbers stored at location LIST_IN. The list is already sorted in an ascending order. The first element is the number, n, which is the length of the array. The subroutine will copy the elements from location LIST_IN to location LIST_OUT. While copying, if an element appears more than once (repeated), then the repeated copies are ignored. In essence, the subroutine eliminates the replicated elements from LIST_IN and places the results in LIST_OUT. Note that you need to update number m (the first element on the top) which is the actual number of elements in LIST_OUT after eliminating all replicates.
Skeleton key is included below, most of the code is already done all that is needed is the code for the loop portion. Should be less than 10 lines of code.
;set the pointers REPFR mov.w #LIST_IN, R4 ;set pointer to LIST_IN array mov.w #LIST_OUT, R5 ;set pointer to LIST_OUT array mov.w R5, R6 ;save R6 as a pointer where m need to be stored clr.w R10 ;counter for the updated m number
;get the n number an exit if the array is empty mov.w @R4+, R11 ;save n number in R11 as a loop counter jz done ;exit if LIST_IN is empty incd.w R5 ;manually increment the pointer to LIST_OUT array
;copy the first element to LIST_OUT, and exit if that is the only element mov.w @R4+, 0(R5) ;copy first element from LIST_IN to LIST_OUT incd R5 ;manually increment pointer R5 inc R10 ;increment the m counter to count for first element move dec R11 ;decrement the n counter to count for first element move jz done
;create a loop to compare the next element to the one before it, and if different copy it to ;the LIST_OUT, but if it is the same skip copying, then check the loop counter and loop again.
loop ------- ------- ;enter your code here, less than 10 lines ------- -------
done mov.w R10, 0(R6) ;save the m value at the top of the LIST_OUT array ret
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
