ARM: Attempt to write to my own declared .space variable causes a segmentation fault

0

I'm playing around with ARM assembly in an attempt to learn and keep my skills improving. An integral part to any assembly program is the ability to store values in memory. My problems begin here.

I have a section of memory which I have set aside using the .space directive and given it 4 bytes. This should be a writable address in memory, especially since I know that it is word aligned (I checked when I disassembled).

I have tried not using a data section - segmentation fault when attempting to write. I have tried putting my memory into a data section - it won't compile.

    .global main

main:
    push    {lr}        @ push return address

rdc:
    adr     r0, Fs
    push    {r0}        @ printf will stomp all over r0, so save it off
    bl      printf      @ Prints "FFF\n"
    pop     {r0}        @ restore r0
    ldr     r0, [r0]
    str     r0, workarea @ this causes a segmentation fault

gohome:
    pop     {pc}        @ pop return address directly into pc counter

    @ .data directive was added to skirt around segmentation fault
    @ caused by str r0,workarea. I figured that because it's in the
    @ code section that it's static and unalterable. But now I get
    @ "symbol .data is in a different section" which may indicate
    @ that my .text and .code  are non-contiguous in virtual memory
    @ during compile-time.
    .data

Fs:
    .word   0x0A464646  @ 3 'F' characters and a line feed
workarea:
    .space  4           @ want to move Fs into this area
nullterm:
    .word   0x00000000  @ operates as a null terminating character

    .end

So, how can I put the contents of R0 into my workarea memory location?

edit

I put the .data directive at the top of my assembly and it works just fine. So I guess my question really boils down to understanding data/code regions. It seems to me that using the .data region for everything is bad form because it makes the code editable as well.

segmentation-fault
arm
asked on Stack Overflow Feb 2, 2019 by Timothy Eckstein • edited Feb 3, 2019 by Timothy Eckstein

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0