ARM程序集将寄存器存储到内存

时间:2014-04-26 23:50:32

标签: assembly arm

我有以下简单程序对两个向量执行操作; A和B(存储在内存中)并将结果保存回向量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工作正常,直到STR R5, [R2]指令。该指令似乎没有更新内存(R2指向的地址保持不变;即,它是0x00)。我一直在努力解决这个问题几个小时,并且完全不知道出了什么问题。数据部分明确地说READWRITE,所以我不明白为什么内存不会更新。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我想出了问题所在。我正在使用Keil模拟器,显然我不得不手动映射我要写的内存段。我在程序运行时单击Debug -> Memory Map...菜单,然后映射了一个段范围并赋予了Read, Write, Execute权限。

enter image description here

相关问题