Question: Write a procedure labeled merge: that will merge two sorted arrays in memory into a single sorted array. Arguments are as follows: x 0 :
Write a procedure labeled merge: that will merge two sorted arrays in memory into a single sorted array. Arguments are as follows:
x: length of first array
x: address of first element of the first array
x: length of the second array
x: address of first element of the second array
x: address at which to write the sorted array. Guaranteed to be able to hold xx elements.
Note: all elements are unsigned bit values. Sorting is from smallest to largest.
Hints:
You should write this function first in Python or C to figure out the process before trying to write it in assembly.
It's a bit easier to write assembly loops that have the index count down.
xand x and x is not just the base of an array, it's also a pointer to the first address in the array. "add xx will change the pointer to the next location in the array if your code doesn't need to "remember" the base.
Don't forget that you may run out of values in one or the other of the lists, and you'll need to continue copying the rest of the other list. Feel free to use code you've figured out from the previous question.
My code:merge:
MOV x #
MOV x #
MOV x x
MOV x x
MOV x x
ADD x x x
mergeloop:
CMP x x
BEQ arr
CMP x x
BEQ arr
LDR xx
LDR xx
CMP x x
BLE arrsm
STR xx #
ADD x x #
ADD x x #
B mergeloop
arrsm:
STR xx #
ADD x x #
ADD x x #
B mergeloop
arr:
SUBS x x x
BLE end
ADD x x #
ADD x x x LSL #
ADD x x x
B cparr
arr:
SUBS x x x
BLE end
ADD x x #
ADD x x x LSL #
ADD x x x
cparr:
LDR xx #
STR xx #
SUBS x x #
BNE cparr
cparr:
LDR xx #
STR xx #
SUBS x x #
BNE cparr
end:
RET
Test:
array
array
Expected:
Got:
Run error
Traceback most recent call last:
File testerpython line in
armsim.run
File usrlocallibpythonsitepackagesarmsimpy line in run
executeline
File usrlocallibpythonsitepackagesarmsimpy line in execute
raise ValueErrorUnsupported instruction or syntax error: line
ValueError: Unsupported instruction or syntax error: add xxxlsl
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
