Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

Step: 3

blur-text-image

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago