You are to write a program that does the following: 1. Copy the contents of sour
ID: 3766583 • Letter: Y
Question
You are to write a program that does the following:
1. Copy the contents of sourceArray to the area of static RAM starting at location 0x40000000
2. Sort the contents of the copied array in ascending order using a shell sort.
Part of the program has been provided below; you need only write the code for the copyArray and shellSort subroutines. Note that arguments are passed to the subroutines using registers. Submit the .s file of your program through Blackboard. Be sure to document you program well.
AREA ShellSort, CODE, READONLY
destinationArray EQU 0x40000000
ENTRY
LDR r0,=sourceArray
LDR r1,=destinationArray
MOV r2,#arraySize
BL copyArray
LDR r0,=destinationArray
MOV r1,#arraySize
BL shellSort
stop B stop
copyArray
;Address of source array passed in R0
;Address of destination array passed in R1
;Number of array elements passed in R2
;YOUR CODE GOES HERE
MOV PC,LR ;Return to calling subroutine
shellSort
;Address of source array passed in R0
;Number of array elements passed in R1
;YOUR CODE GOES HERE
MOV PC,LR ;Return to calling subroutine
arraySize EQU 20
sourceArray DCD -9,23,-100,675,2,98,13,-4,1000,23,5,234,45,67,12,-2,54,2,17,99
END
Here is a c version of the shell sort to help you get started:
void ShellSort( int num[ ], int aSize) {
int temp;
bool swapFlag = true;
int distance = aSize;
while( swapFlag || (distance > 1)) {
swapFlag = false;
distance = (distance+1) / 2;
for (int i = 0; i < (aSize - distance); i++) {
if (num[i + distance] < num[i]) {
//Swap values at positions i+distance and i
temp = num[i + distance];
num[i + distance] = num[i];
num[i] = temp;
swapFlag = true;
} //end if
} //end for
} //end while
}// end ShellSort
Explanation / Answer
1. Copy the contents of sourceArray to the area of static RAM starting at location 0x40000000
KEEP_SECTION { .vectortable }
MEMORY {
interrupts (RX) : ORIGIN = 0x80000000, LENGTH = 0x00000300
code (RX) : ORIGIN = 0x80000300, LENGTH = 0x00005354
data (RW) : ORIGIN = 0x80005654, LENGTH = 0x000029AC
}
SECTIONS {
.interrupts :AT (0x04000000)
{
___VECTOR_RAM = .;
* (.vectortable)
. = ALIGN (0x4);
} > interrupts
.text :AT (0x04000000 + SIZEOF(.interrupts))
{
* (.text)
. = ALIGN(0x4);
* (.rodata)
. = ALIGN(0x4);
___ROM_AT = .;
___DATA_ROM = .;
} > code
.data : AT (0x04000000 + SIZEOF(.interrupts) + SIZEOF(.text)) #AT(___ROM_AT)
{
___PLL_CODE_START =.;
* (.changePllCode)
. = ALIGN(0x4);
___PLL_CODE_END =.;
___PLL_CODE_SIZE = ___PLL_CODE_END - ___PLL_CODE_START;
___DATA_RAM = .;
* (.exception)
. = ALIGN(0x4);
__exception_table_start__ = .;
EXCEPTION
__exception_table_end__ = .;
___sinit__ = .;
STATICINIT
___DATA_START =.;
* (.data)
. = ALIGN (0x4);
___DATA_END =.;
__SDATA_START =.;
* (.sdata)
. = ALIGN (0x4);
__SDATA_END = .;
__SDA_BASE = .;
. = ALIGN(0x4);
} > data
.bss : AT (0x04000000 + SIZEOF(.interrupts) + SIZEOF(.text) + SIZEOF(.data))
{
__START_SBSS = .;
* (.sbss)
*(SCOMMON)
__END_SBSS = .;
__START_BSS = .;
* (.bss)
* (COMMON)
__END_BSS = .;
. = ALIGN(0x4);
} >> data
# Heap and Stack sizes definition
___heap_size = 0x400;
___stack_size = 0x400;
# 32 Kbytes Internal SRAM
___RAMBAR = 0x80000000;
___RAMBAR_SIZE = 0x00008000;
___SP_AFTER_RESET = ___RAMBAR + ___RAMBAR_SIZE - 4;
___SP_SIZE = 0x0400;
___HEAP_START = .;
___HEAP_END = ___HEAP_START + ___heap_size;
___SP_END = ___HEAP_END;
___SP_INIT = ___SP_END + ___stack_size;
___heap_addr = ___HEAP_START;
___heap_size = ___HEAP_END - ___HEAP_START;
__SP_INIT = ___SP_INIT;
# _romp_at = ___ROM_AT + SIZEOF(.data);
_romp_at = 0x04000000 + 0x8000 ;
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
WRITEW(0x04000000);
WRITEW(0x80000000);
WRITEW(0x7fff);
WRITEW(0);
WRITEW(0);
WRITEW(0);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.