Mert Arisoy
Mert Arisoy

Reputation: 65

Storing values in Array in ARM-Assembly

I have a predefined array in ARM-Assembly like

Sample  DCD 0x003, 0x004, 0x005, 0x006

I just want to change indexes of Sample[0] and Sample[1]

And I wrote a ARM-Assembly code for swapping

LDR R0, =Sample
LDR R1, [R0]
LDR R2, [R0, #4]
MOV R3, R1
MOV R1, R2
MOV R2, R3
STR R1, [R0]
STR R2, [R0, #4]

And I fetching the data one by one into R4 like

MAIN
LDR R4, [R0], #4
B MAIN

It looks like so simple but array is not changing, it still same

How can I change the indexes?

Briefly my input is

Sample  DCD 0x003, 0x004, 0x005, 0x006

And I want the output like

Sample  DCD 0x004, 0x003, 0x005, 0x006

Upvotes: 0

Views: 3360

Answers (1)

chocovore17
chocovore17

Reputation: 33

Your array is not changing because you need to ADR the arrow before loading it. Your code is not doing anything because you don't load the memory address. This would work.

   ADR     R0, Sample
   LDR     R1, [R0]
   LDR     R2, [R0, #4]
   MOV     R3, R1
   MOV     R1, R2
   MOV     R2, R3
   STR     R1, [R0]
   STR     R2, [R0, #4]

Upvotes: 2

Related Questions