Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code not working Question working on: The program of this exercise deals with arrays of numbers and subroutines. At the beginning of your program you

code not working

Question working on: The program of this exercise deals with arrays of numbers and subroutines. At the beginning of your program you will allocate empty storage for two original arrays and their sorted versions. For the overall program layout, use the program skeleton file (lab2-v32-inA-skl).

Complete the above MSP430 assembly language program where the SORT1 part sets the R4/R5/R6 parameters, which are used by the SORT subroutine to sort array ARY1. R5 holds the starting address of the array. R4 holds the length of the array. R6 holds the starting location of the sorted Array. SORT2 code is similar to SORT1 above using same registers. Arrays are in decimal notation! Sort Arrays in increasing order from lowest to highest value.

The code I have built is this: (italics is what was given at beginning of code) (* errors marked when run)

;Memory allocation of arrays must be done prior to the RESET & StopWDT ARY1 .set 0x0200 ;Memory allocation ARY1 ARY1S .set 0x0210 ;Memory allocation ARYS ARY2 .set 0x0220 ;Memory allocation ARY2 ARY2S .set 0x0230 ;Memory allocation AR2S ;------------------------------------------------------------------------------- ; Main loop here ;-------------------------------------------------------------------------------

clr R4 ;Clear Register clr R5 ;Clear Register clr R6 ;Clear Register

SORT1 mov.w #ARY1, R4 ;Intialize R4 to poin to ARY1 in the memory mov.w #ARY1S, R6 ;Intialize R6 to poin to ARY1S in the memory where the sorted ARY1 will be stored call #ArraySetup1 ;Creat elements are store them in ARY1 call #COPY ;Copy the elements from the ARY1 space to ARY1S space call #SORT ;Calling Subroutine Sort with parameter passing in R4 abd R6

SORT2 mov.w #ARY2, R4 ;Intialize R4 to poin to ARY2 in the memory mov.w #ARY2S, R6 ;Intialize R6 to poin to ARY2S in the memory where the sorted ARY2 will be stored call #ArraySetup2 ;Creat elements are store them in ARY2 call #COPY ;Copy the elements from the ARY2 space to ARY1S space call #SORT ;Calling Subroutine Sort with parameter passing in R4 abd R6

SORT clr R7 clr R8 clr R9 clr R10 clr R11 clr R12 clr R13 clr R14 clr R15

clr R10 mov.b R5, R11 ; counter dec R11

mov.b @R4+, R7 mov.b @R4, R8 cmp.b R7, R8 * jz no_swarp * jge no_swap

mov.b R7, R9 mov.b R8, R7 mov.b R9, R8 * cnc R10 mov.b R8, 0(R4) mov.b R7, -1(R4)

dec R11 tst R11 * jnz swap * cmp.w #0 R10 ; swap counter * jnz swap

ret

Mainloop jmp Mainloop ;loop in place for ever

;Array element intitialization Subroutine ArraySetup1 mov.b #10, 0(R4) ;Define the number of elements in the array mov.b #20, 1(R4) ;store an element mov.b #89, 2(R4) ;store an element mov.b #-5, 3(R4) ;store an element mov.b #13, 4(R4) ;store an element mov.b #63, 5(R4) ;store an element mov.b #-1, 6(R4) ;store an element mov.b #-88, 7(R4) ;store an element mov.b #2, 8(R4) ;store an element mov.b #-88, 9(R4) ;store an element mov.b #-1, 10(R4) ;store an element ret

;Array element intitialization Subroutine ArraySetup2 mov.b #10, 0(R4) ;Define the number of elements in the array mov.b #90, 1(R4) ;store an element mov.b #-10, 2(R4) ;store an element mov.b #-45, 3(R4) ;store an element mov.b #25, 4(R4) ;store an element mov.b #-46, 5(R4) ;store an element mov.b #-8, 6(R4) ;store an element mov.b #99, 7(R4) ;store an element mov.b #20, 8(R4) ;store an element mov.b #0, 9(R4) ;store an element mov.b #-64, 10(R4) ;store an element ret

;Copy original Array to allocated Array-Sorted space 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 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

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions