This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STR instruction fails in Assembly

Hello everyone,

I have written this piece of code that implements Bubble Sort in assembly. I declared an unsorted array with 10 elements with the DCD directive and then I have made register R0 indicate to the first element of this array. Then I implemented the Bubble Sort as below:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
; Bubble Sort algorithm in Assembly ;)
AREA BubbleSort, CODE, READONLY
ENTRY
EXPORT __main
GLOBAL bsort
__main
bsort
;Bubble sort that works on 32bit integers
;R0 = array location, R1 = array size
;ADRL R0, Vals ;R0 - array location
LDR R0, =ARRAY
MOV R1, #Size
bsort_next
MOV R2, #0 ;current element number
MOV R6, #0 ;number of swaps
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This is the unsorted array declared with the DCD directive. I can see it in SRAM:

As you can see I store the values for the current and next element in R4 and R5 registers so I can compare them.

Right below that line I compare the two and attempt to do a swap if current>next:

In the first iteration for example current(R4) is 9 and next(R5) is 1 so there should be a swap. The STRGTs below the compare execute however when I look at the RAM in the memory window nothing is changed there. I was expecting to see the swap on the memory itself but the image is exactly like the one with the memory view above. Basically no swap takes place into the memory itself even tough the two conditional STR instructions get executed.

Can someone please help me understand why this is happening so I can fix the issue? Thank you for reading!

Some remarks:

- I have initially declared the array in a separate DATA  section but I could not even see it as initialized with the memory window. I did some reading and I found out  that happens because I have not written a piece of code that would copy that array from the FLASH and store it into RAM so I have declared the array into the CODE section so I can see it with the debugger.

- I'm not using any hardware I'm using the simulator in keil for this exercise. Not sure if that is problematic or not.

0