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

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

问题描述

我有以下简单的程序可以对两个向量执行操作;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 ->程序运行时的内存映射...菜单,然后我映射了一个段范围并赋予它读、写、执行权限.

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 程序集将寄存器存储到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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