Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to Microprocessors Here is the problem: The following is the skeleton that we are provided: ;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with

Intro to Microprocessors

Here is the problem:

image text in transcribed

The following is the skeleton that we are provided:

;------------------------------------------------------------------------------- ; MSP430 Assembler Code Template for use with TI Code Composer Studio ;------------------------------------------------------------------------------- .cdecls C,LIST,"msp430.h" ; Include device header file .def RESET .text ; Assemble into program memory .retain ; Override ELF conditional linking and retain current section .retainrefs ; Additionally retain any sections that have references to current section

;------------------------------------------------------------------------------- RESET mov.w #__STACK_END,SP ; Initialize stackpointer StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer

;------------------------------------------------------------------------------- ;----- Your Sorting lab starts here -------------------------------------------

;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

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

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

;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 nop ret ;To bubble sort, you need to scan the array n-1 times, ;and in every scan you compare from top down each two consecutive elements, ;and you swap them if they if they are not in ascending order. ;Notice that in the first scan you get the largest element pushed all the way to the bottom, ;so your next scan should be n-1, 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.

;Your sorting algorithm starts with R6 as a pointer to the array ;you need to save n (number of elements) in R8, then decrement it by 1 (n-1) to become the number of comparisons. ;Copy R6 to R7 so you keep R6 unchanged pointing to the top of the array for every new scan. ;Copy n-1 to R9 as a loop counter, while keeping n-1 in R8 for the next scan. ;In the scan loop get an element and auto increment pointer R7, then get next element without changing R7. ;Compare the two elements, if not in ascending order, swap them. ;Repeat the scan from the top (always R6), and every time decrement the number of comparisons (R8).

;----- Your Sorting lab ends here ------------------------------------------- ;-------------------------------------------------------------------------------

;------------------------------------------------------------------------------- ;Stack Pointer definition .global __STACK_END .sect .stack ;------------------------------------------------------------------------------- ;Interrupt Vectors .sect ".reset" ;MSP430 RESET Vector .short RESET

[14] 2) 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). Memory allocation of Arrays must be done before the RESET and StopWDT ARY1 Memory allocation set 0x0200 ARY1 Memory allocation ARY1S set 0x0210 ARYS Memory allocation ARY2 set 0x0220 ARY2 Memory allocation ARY 2S set 0x0230 AR2S Main Block cl clearing all register being use is a good cl programming practice SORT1 #ARY 1, R5 initiali R5 as rray1 a pointe r to mov W Ze EARTY 15 R6 initiali R6 as rray1 sorted. a pointe r to mov W Ze #Array Setup the call subroutine Array Setup call Call SORT the call subroutine SORT SORT2 subroutine SORT sorts array from SORT lowest to highest value jmp Main loop :Infinite Loop Mainloop Array Setup1 mov.b #10 0 (R5) Memory allocation Subroutine mov.b (R5) with the number of elements #1 irst start mov b #2 2(R5) d then fill in the element ret Main Block [10] 2.a) Complete the above MSP430 assembly language program where the SORT1 part sets the R4/RS/R6 parameters, which are used by the SORT subroutine to sort array ARYl. RS 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. Main Program: [3] for Program setup, and [7 for Sort Subroutine ARY1 (17,55, 9,22,36, 7,37,8,-77,8) ARY2 (14,-74,-23,19, 72, 7,44,60,0,-39) [14] 2) 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). Memory allocation of Arrays must be done before the RESET and StopWDT ARY1 Memory allocation set 0x0200 ARY1 Memory allocation ARY1S set 0x0210 ARYS Memory allocation ARY2 set 0x0220 ARY2 Memory allocation ARY 2S set 0x0230 AR2S Main Block cl clearing all register being use is a good cl programming practice SORT1 #ARY 1, R5 initiali R5 as rray1 a pointe r to mov W Ze EARTY 15 R6 initiali R6 as rray1 sorted. a pointe r to mov W Ze #Array Setup the call subroutine Array Setup call Call SORT the call subroutine SORT SORT2 subroutine SORT sorts array from SORT lowest to highest value jmp Main loop :Infinite Loop Mainloop Array Setup1 mov.b #10 0 (R5) Memory allocation Subroutine mov.b (R5) with the number of elements #1 irst start mov b #2 2(R5) d then fill in the element ret Main Block [10] 2.a) Complete the above MSP430 assembly language program where the SORT1 part sets the R4/RS/R6 parameters, which are used by the SORT subroutine to sort array ARYl. RS 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. Main Program: [3] for Program setup, and [7 for Sort Subroutine ARY1 (17,55, 9,22,36, 7,37,8,-77,8) ARY2 (14,-74,-23,19, 72, 7,44,60,0,-39)

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

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Demonstrate three aspects of assessing group performance?

Answered: 1 week ago