Question: Hi I need help with this ARM assembly quicksort program. I'm a beginner and very confused with ARM 90% of the time, so I'm sorry
Hi I need help with this ARM assembly quicksort program. I'm a beginner and very confused with ARM 90% of the time, so I'm sorry in advance. I can't tell if it is correct or incorrect.
assignment description: You are to convert the following C quicksort program to ARM assembler. There are numerous websites that describe the quicksort algorithm.
Your program must follow these conventions:
A calling function must use a stack to pass arguments to the called function. When the called function returns, it is the responsibility of the calling function to remove the arguments from the stack.
All registers that a called function will be using to perform calculations must first be pushed onto the stack along with the return address in r14. This is typically the first instruction of the function. When it is time for the function to return, the registers will be restored to their original values. The return address will be popped into the pc.
You may use any of the 4 stack types.
Make you program scalable so that it is easy to change the array size.
Your quicksort sorts an array of unsigned words (DCD) into ascending order.
Before sorting you will need to copy the array to address 0x40000000.
here is my code:
SRAM EQU 0x40000000
AREA Program5, CODE, READONLY ENTRY base RN 0 left RN 1 right RN 2 i RN 3 j RN 4 min RN 5 pivot RN 6 array RN 7 temp RN 8 ADR r10, =SRAM LDRB array, sourceArraySize LSR array, array, #2 MOV r8, array LDR r6, =sourceArray
int
LDR r11, [r6], #4 STR r11, [r10], #4 SUBS r8,r8,#1 BNE int MOV sp, r10 LDR base, =SRAM MOV left, #0 SUB right, array, #1 STMDB sp!, {base, left,right} BL quicksort quicksort
STMIA sp!, {r3-r7,r9,lr} LDR base, [sp, #-40] LDR left,[sp, #-36] LDR right, [sp, #-32] ADD min, left, right LSR min, min, #1 MOV i, left MOV j, right LDR pivot,[base, min, LSL #2] loop
CMP left, j BLT loop2 CMP i, right BLT loop2
loop2
LDR r8, [base, i, LSL #2] CMP r8, pivot ADDLT i,i, #1 BLT loop2 B return
loop3
LDR r8, [base,i, LSL #2] CMP r8, pivot SUBGT j,j, #1 BGT loop3 CMP i, j BLE if BGT else
if
LDR r8, =sourceArray LDR r8, [r8, i,LSL #2] MOV temp, r8 LDR r8,[base, j, LSL #2] STR r8, [base, i, LSL #2] STR r8,[base, j, LSL #2] ADD i,i, #1 SUB j,j, #1 B loop
else
CMP left,j BLT quickJ CMP i, right BLT quickI B return
quickJ
MOV right, j STMIA sp!, {base,left,j} BL quicksort LDMDB sp!, {base, left, j} quickI
MOV left, i STMIA sp!, {base, i, right} BL quicksort LDMDB sp!, {base, i, right return LSMDB sp!, {r3-r7,r9, pc} stop b stop
sourceArray DCD 110, 5, 10, 3 ,22, 100, 1, 23, 6, 12, 654, 1 sourceArraySize DCB (sourceArraySize- sourceArray) END
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
