Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to swap to elements in an array in ARM Assembly, I have the code started I just need help finishing the final subroutine.

I need to swap to elements in an array in ARM Assembly, I have the code started I just need help finishing the final subroutine. the swap_array subroutine swaps two elements of an array, given the address of the array and two (valid) indexes of that array. Use a temp variable on the stack as part of the swap.

@ Swap the array data MOV R1, #1 STMFD SP!, {R1} @ Push j MOV R1, #7 STMFD SP!, {R1} @ Push i LDR R1, =Data STMFD SP!, {R1} @ Push a BL swap_array ADD SP, SP, #12 BL PrintLF

@-------------------------------------------------------

PrintLF:

/*

-------------------------------------------------------

Prints the line feed character ( )

-------------------------------------------------------

Uses:

R0 - set to ' '

(SWI_PrChr automatically prints to stdout)

-------------------------------------------------------

*/

STMFD SP!, {R0, LR}

MOV R0, #' ' @ Define the line feed character

SWI SWI_PrChr @ Print the character to Stdout

LDMFD SP!, {R0, PC}

@-------------------------------------------------------

swap_array:

/*

-------------------------------------------------------

Swaps location of two values in list. swap(a, i, j)

Parameters passed on stack:

Address of list

Index of first value (i)

Index of second value (j)

Local variable

temp

-------------------------------------------------------

Uses:

-------------------------------------------------------

*/

STMFD SP!, {FP, LR} @ push frame pointer and link register onto the stack

MOV FP, SP @ save current stack top to frame pointer

SUB SP, SP, #4 @ set aside space for temp

STMFD SP!, {?} @ preserve other registers

@ your code here

LDMFD SP!, {?} @ pop preserved registers

ADD SP, SP, #4 @ remove local storage

LDMFD SP!, {FP, PC} @ pop frame pointer and program counter

@-----------------------------------------------------

.data Data: .byte 4,5,9,0,8,0,8,7,1 @ The list of data _Data: @ End of list address .end

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions