how can i use store registers in memory in CODE section that is ReadOnly (ARM Assembly)?

689 views Asked by At

here's my code :

AREA Swap, CODE

ENTRY
    EXPORT __main

__main

ADR R0, VAR_1
ADR R1, VAR_2
LDR R2, [R0]
LDR R3, [R1]

STR R2, [R1]
STR R3, [R0]

stop    B   stop

AREA Swap, DATA, READWRITE

VAR_1 DCD 8
VAR_2 DCD 7

END

i can load values from addresses (r0 and r1) but i cant store them. i know that CODE section is read only but if I add READWRITE keyword the code doesn't work properly.when i run debugger the only thing that is execute is MOV r0, r0 enter image description here

I tried to change memory map permissions like the answer in this question : ARM Assembly storing registers to memory but it doesn't work

enter image description here

Any help is appreciated.

1

There are 1 answers

0
Elliot Alderson On

You haven't specified your target processor, but it sounds like the CODE space is in Flash memory. As a general rule, the program Flash memory really is read-only at run time. At best you would go through a very specific and careful procedure to modify part of the Flash. You can't change the physical nature of the memory just by declaring it to be READWRITE for the linker.