Question

I have the following simple program that performs an operation on two vectors; A and B (which are stored in memory) and saves the result back into memory pointed to by vector C:

        AREA MyProgram, CODE, READONLY
        ENTRY

Start   ADR R0, VecA
        ADR R1, VecB
        ADR R2, VecC

        ; R6 is a counter
        MOV R6, #1

Loop    ; Get the value R0 is pointing to
        LDR R3, [R0], #4

        ; Get the value R1 is pointing to
        LDR R4, [R1], #4

        ; Add the values
        ADD R5, R4, R3

        ; Divide the value by 2 (i.e. shift right by 1)
        LSR R5, #1

        ; Store the resut to memory for C
        STR R5, [R2]

        ; Increment R2 to point to the next memory location
        ADD R2, R2, #4

        ; Increment the counter. If it's 9, we're done
        ; (since the vector has 8 elements)
        ADD R6, R6, #1

        CMP R6, #9
        BNE Loop
        B Done

Done    b Done ; Loop forever


        AREA MyProgram, DATA, READWRITE

VecA    DCD 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9
VecB    DCD 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9
VecC    DCD 0x0


        END

Eveything works fine up until the STR R5, [R2] instruction. The instruction doesn't seem to update the memory (the address pointed to by R2 remains unchanged; that is, it's 0x00). I've been trying to figure this out for a few hours now and absolutely have no idea what's going wrong. The data section explicitly says READWRITE, so I don't understand why the memory doesn't get updated. Any help is greatly appreciated.

Était-ce utile?

La solution

I figured what the problem was. I'm using Keil simulator and apparently I had to manually map the memory segments that I'd be writing to. I did this by clicking the Debug -> Memory Map... menu while the program was running and then I mapped a segment range and gave it Read, Write, Execute privileges.

enter image description here

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top