Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bubble Sort Assembly code please help Complete this MSP430 assembly language program where the SORT1 section sets theR4/R5/R6 parameters, which are used by the COPY

Bubble Sort Assembly code please help

Complete this MSP430 assembly language program where the SORT1 section sets theR4/R5/R6 parameters, which are used by the COPY and SORT subroutines to copy and sortarray ARY1. R4 holds the starting address of the array. R5 holds the length of the array. R6 holdsthe starting location of the sorted array. COPY subroutine copies the contents of array ARY1

into ARY1S. SORT subroutine sorts the elements on ARY1S in place.

SORT2 section is similar to SORT1 above using same registers. Arrays are in decimal notation!

Sort Arrays in increasing order from lowest to highest value. Main Program: [6] for Program setup, and [10] for Sort Subroutine. Use these values for the array elements. ARY1: (17,75,-67,23,36,-7,44,8,-74,18), ARY2: (54,-4,-23,-19,-72,-7,36,62,0,39)

here is what i got so far i am working on the SORT part of it if any help please and thank you.

clr R4 ;clearing all register being use is a good clr R5 ;programming practice clr R6

SORT1 mov.w #ARY1, R4 ;initialize R4 as a pointer to array1 mov.w #ARY1S, R6 ;initialize R4 as a pointer to array1 sorted call #ArraySetup1;then call subroutine ArraySetup1 call #COPY ;Copy elements from ARY1 to ARY1S space call #SORT ;Sort elements in ARAY1

SORT2 mov.w #ARY2, R4 ;initialize R4 as a pointer to array2 mov.w #ARY2S, R6 ;initialize R4 as a pointer to array2 sorted call #ArraySetup2;then call subroutine ArraySetup2 call #COPY ;Copy elements from ARY2 to ARY2S space call #SORT ;Sort elements in ARAY2

Mainloop jmp Mainloop ;Infinite Loop

ArraySetup1 mov.b #10, 0(R4) ; Array element initialization Subroutine mov.b #17, 1(R4) ;First start with the number of elements mov.b #75, 2(R4) ;and then fill in the 10 elements. mov.b #-67, 3(R4) mov.b #23, 4(R4) mov.b #36, 5(R4) mov.b #-7, 6(R4) mov.b #44, 7(R4) mov.b #8, 8(R4) mov.b #-74, 9(R4) mov.b #18, 10(R4) ret

ArraySetup2 mov.b #10, 0(R4) ;Define the number of elements in the array mov.b #54, 1(R4) ;store an element mov.b #-4, 2(R4) ;store an element mov.b #-23, 3(R4) mov.b #-19, 4(R4) mov.b #-72, 5(R4) mov.b #-7, 6(R4) mov.b #36, 7(R4) mov.b #62, 8(R4) mov.b #0, 9(R4) mov.b #39, 10(R4) ret

COPY mov.b 0(R4), R10 ;save n (number of elements) in R10 inc.b R10 ;increment by 1 to account for the byte n to be copied as well mov.w R4, R5 ;copy R4 to R5 so we keep R4 unchanged for later use mov.w R6, R7 ;copy R6 to R7 so we keep R6 unchanged for later use ret

LP mov.b @R5+, 0(R7) ;copy elements using R5/R7 as pointers inc.w R7 dec R10 jnz LP ret

;Sort the copy of Array saved in the allocated Array-Sorted space, while keeping original Array unchanged ;replace the following two lines with your actual sorting algorithm. ;Sort the copy of Array saved in the allocated Array-Sorted sapce, while keeping original Array unchanged SORT nop

ret

;To bubble sort, you need to scan the array n-1 times, ;In every scan, you compare from top down each two consecutive elements, and you swap them if they are not in ascending order. ;Notice that in the first scan you get the largest element (no matter where it is in the array) pushed all the way to the bottom. ;So your next scan should be n-1 iterations, and then n-2 and so on. ;So every time you come back to the top of the array for a new scan, your n (the number of comparisons) must be decremented by 1. ;In the last scan, you need only one comparison.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

1. How does Kiwi Experience maintain a continual customer focus?

Answered: 1 week ago