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

ARM 7 Assembly memory areas are not initialized

I am trying to write simple program using ARM 7 Assembly, but I cannot initialize memory region with simple data. Here is an example

    AREA    RESET, CODE, READWRITE
    ENTRY
    LDR   r0, =SortArray ;load start address
    LDR   r1, =SortArrayEnd ; load end address
    STR  r15, [r0]
    LDR r4, [r0]
    SUB r2, r2, #1 ; r2 contains (LENGTH-1)
    MOV r6, #0 ; r6 sum set to 0
STOP B STOP
    LTORG
    AREA my_data, DATA, READWRITE
    ALIGN
SortArray
    DCD 1,5,20,32,13,66,3,5,23,64,112,66,22
SortArrayEnd

    END


This doesn't loads data in memory, in debug mode SortArray in r0 register points to 0x40000000 and SortArrayEnd points to 0x40000034, but there is no data

Memory map for data in separate area - i.stack.imgur.com/JNAK2.png

But as you may have noticed there is instruction for storing data in the memory STR r15, [r0] and it works perfectly data is stored there.

Next example works but as you can see I placed data inside code area and made it READWRITE that is probably bad idea. But in this case I can see my data in the memory.

    AREA    RESET, CODE, READWRITE
SortArray
    DCD 1,5,20,32,13,66,3,5,23,64,112,66,22
SortArrayEnd
    ENTRY
    LDR   r0, =SortArray ;load start address
    LDR   r1, =SortArrayEnd ; load end address
    STR  r15, [r0]
    LDR r4, [r0]
    SUB r2, r2, #1 ; r2 contains (LENGTH-1)
    MOV r6, #0 ; r6 sum set to 0
STOP B STOP
    LTORG

    END


Here is my memory map it starts from 0x00000000

Memory Map WIth Data placed in code Area - i.stack.imgur.com/Vfkwf.png

Please help to find the problem, I have spent several days trying to figure out what is wrong.

I am using uVision 4 and device is LCP2148.

Parents
  • When the processor starts the RAM holds random content, you must copy whatever you need to it from ROM. You need to implement an equivalent to memcpy and memset to do the work of setting up the RAM.

    Using the runtime library to do your donkey work should look something like this

    ; ...
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    
    Stack_Mem       SPACE   1024
    Stack_Top
    
    ; ...
    
                    AREA    RESET, CODE, READONLY
                    ARM
    
    Vectors         LDR     PC, Reset_Addr
    
    ; ...
    
    Reset_Addr      DCD     Reset_Handler
    
    ; ...
    
    
    ; Reset Handler
    
                    EXPORT  Reset_Handler
    Reset_Handler
    
                    LDR     R0, =Stack_Top
                    MOV     SP, R0
    
                    IMPORT  __main
                    LDR     R0, =__main
                    BX      R0
    
                    EXPORT  main
    main
    
    ; Your code
    
    ; ...
    
                    AREA |.data|, DATA, READWRITE
                    ALIGN
    
    foo             DCD 1,2,3,4,5,6
    
                    END
    

Reply
  • When the processor starts the RAM holds random content, you must copy whatever you need to it from ROM. You need to implement an equivalent to memcpy and memset to do the work of setting up the RAM.

    Using the runtime library to do your donkey work should look something like this

    ; ...
    
                    AREA    STACK, NOINIT, READWRITE, ALIGN=3
    
    Stack_Mem       SPACE   1024
    Stack_Top
    
    ; ...
    
                    AREA    RESET, CODE, READONLY
                    ARM
    
    Vectors         LDR     PC, Reset_Addr
    
    ; ...
    
    Reset_Addr      DCD     Reset_Handler
    
    ; ...
    
    
    ; Reset Handler
    
                    EXPORT  Reset_Handler
    Reset_Handler
    
                    LDR     R0, =Stack_Top
                    MOV     SP, R0
    
                    IMPORT  __main
                    LDR     R0, =__main
                    BX      R0
    
                    EXPORT  main
    main
    
    ; Your code
    
    ; ...
    
                    AREA |.data|, DATA, READWRITE
                    ALIGN
    
    foo             DCD 1,2,3,4,5,6
    
                    END
    

Children
No data