什么是非对齐访问?(ARM/凯尔) [英] What is non-aligned access? (ARM/Keil)

查看:48
本文介绍了什么是非对齐访问?(ARM/凯尔)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Keil 为 ARM 7 编写程序集.

I'm using Keil to write Assembly for ARM 7.

我有以下运行时错误:

Non-aligned Access: ARM Instruction at 000000F8H, Memory Access at 7F7F7F7FH
Data Abort: ARM Instruction at 000000F8H, Memory Access at 7F7F7F7FH

这并没有真正帮助我,因为我不知道什么是非对齐访问"(除了显而易见的,但我真的理解是什么意思)我正在尝试访问(存储)到0x7F7F7F7F,有什么问题?

This doesn't really help me, because I don't know what 'non-aligned access' is, (other than the obvious, but I don't really understand what it means) and I am trying to access (store) to 0x7F7F7F7F, what's the issue?

搜索我只发现了几个类似的问题,都使用 C 语言,并通过一些非常特定于他们的代码的方式解决了,这些问题与这个问题无关.

Searching I only found a couple of similar issues, both using C, and resolved by some means very specific to their code and which didn't relate to this issue.

我在做:

LDR R0, =0x7F7F7F7F
LDR R1, LABEL
STR R1, [R0]

然后我用不同的标签和 R0 的偏移量做了一个类似的事情,但它首先在这里失败.

I then do a similar thing with a different label, and offsets of R0, but it fails here first.

推荐答案

问题是用于 32 位(4 字节)内存操作的地址必须与 4 字节边界对齐.这意味着地址必须是 4 的倍数,或者如果您愿意,地址的底部两位必须为零.

The issue is that the address you use for a 32-bit (4-byte) memory operation must be aligned to a 4-byte boundary. This means the address must be a multiple of 4, or if you prefer, the bottom two bits of the address must be zero.

在这种情况下,最接近的 4 字节对齐地址将是 0x7F7F7F7C0x7F7F7F80.

In this case, the closest 4-byte aligned addresses would be 0x7F7F7F7C or 0x7F7F7F80.

同样,LDRH/STRH 需要 2 字节对齐,而 LDRB/STRB 可以在任何地方操作(1 字节对齐 == 未对齐).

Similarly, LDRH/STRH require 2-byte alignment, whereas LDRB/STRB can operate anywhere (1-byte alignment == unaligned).

一般来说,编译器/汇编器负责确保您的变量正确对齐它们的大小 - 如果您自己生成地址(根据问题),您应该只遇到这种情况.

In general the compiler/assembler takes care of making sure your variables are aligned correctly for the size they are - you should only run into this if you're generating addresses yourself (as per the question).

这篇关于什么是非对齐访问?(ARM/凯尔)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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