Arm/swap

From ASMBits

arm/load2Previous

Write a function that will swap two array elements. Your function will be passed three parameters: The first is a pointer to the beginning of the array. The second and third parameters are indexes to specify which pair of elements of the array should be swapped.

int swap (int *pointer, int index1, int index2);

Expected solution length: Around 7 lines.

Sample Input

r0=Data, r1=0, r2=2

Sample Output

[Two array elements swapped]

Write your solution here

x
 
1
Data: .word 0x123, 0x124, 0x125
2
.global _start
3
_start:
4
    ldr r0, =Data
5
    ldr r1, =0
6
    ldr r2, =2
7
    bl swap
8
    1: b 1b    // Done
9
10
// Swap two array elements
11
swap:
12
    
13
    
Upload a source file...