ARM Assembly将寄存器存储到内存 [英] ARM Assembly storing registers to memory

查看:126
本文介绍了ARM Assembly将寄存器存储到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的程序,可以对两个向量执行操作; A和B(存储在内存中)并将结果保存回向量C指向的内存中:

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

一切工作正常,直到STR R5, [R2]指令为止.该指令似乎并没有更新内存(R2指向的地址保持不变;也就是说,它是0x00).我已经尝试了好几个小时了,而且绝对不知道出了什么问题.数据部分明确显示READWRITE,所以我不明白为什么内存没有更新.任何帮助将不胜感激.

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.

推荐答案

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

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.

这篇关于ARM Assembly将寄存器存储到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆