为什么 STR 仅适用于 0x40000000 和 0x40003FFF 之间的地址? [英] Why does STR only work for addresses between 0x40000000 and 0x40003FFF?

查看:25
本文介绍了为什么 STR 仅适用于 0x40000000 和 0x40003FFF 之间的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

dest EQU 0x40000000

AREA name, CODE, READONLY

ENTRY

MOV r0, #2  
LDR r1, =dest   
STR r0, [r1]    
stop B stop

END

此代码将 2 的值写入内存位置 0x40000000.当我将其更改为 0x20000000 时,2 无法在那里写入.与 0x3FFFFFFF 相同.当我将内存位置设置为 0x40003FFF 时,2 会打印到该位置,但是当我将地址更改为 0x40004000 时,2 无法在那里打印.对于任何更高的地址位置,如 0x50000000,都是一样的.因此,根据这些输出,似乎 STR 仅将值写入 0x40000000 和 0x40003FFF 之间的有限内存范围.

This code writes the value of 2 to memory location 0x40000000. When I change this to 0x20000000, 2 fails to get written there. Same thing with 0x3FFFFFFF. When I set the memory location to 0x40003FFF, 2 gets printed onto that location, but when I change the address to 0x40004000, 2 fails to get printed there. Same thing for any address locations higher, like 0x50000000. So according to these outputs, it seems like STR only writes values onto a finite range of memory between 0x40000000 and 0x40003FFF.

有谁知道为什么会这样?还是我的代码有问题?我使用的是 Keil uVision5、NXP LPC2140.

Does anyone know why this is the case? Or is there something wrong with my code? I am using Keil uVision5, NXP LPC2140.

推荐答案

我找不到LPC2140"的数据表,但我找到了一个似乎是一系列设备的数据表,而具体的你可能是 LPC2142/2144.数据表的第 6.4 节显示 SRAM 映射到0x40000000-0x40003FFF(假设您说的是 16 kB SRAM 变体).这是您应该将其视为通用 RAM 的唯一地址空间.根据数据表,超出该范围的所有内容看起来都很可怕,除非您完全了解自己在做什么,否则应避免使用它.

I couldn't find a datasheet for "LPC2140", but I found a datasheet for what appears to be a family of devices instead, and that the specific one you have could be LPC2142/2144. The datasheet, section 6.4, shows that SRAM is mapped to 0x40000000-0x40003FFF (assuming from what you've said that you have the 16 kB SRAM variant). That's the only address space you should be treating as general purpose RAM. Everything outside that range according to the datasheet looks scary and you should avoid it unless you fully know what you're doing.

您还应该认识到的一件事是 非对齐访问.STR 一次写入一个完整的字(4 个字节),因此地址应该在字边界上对齐.0x40003FFF 未与 4 字节边界对齐;你应该写到 0x40003FFC 代替.如果您只想将单个字节写入 0x40003FFF,则应该使用 STRB 代替.

One thing you should also be cognizant of is unaligned access. STR writes a full word at once (4 bytes) and so the address should be aligned on a word boundary. 0x40003FFF is not aligned to a 4-byte boundary; you should have been writing to 0x40003FFC instead. If you just wanted to write a single byte to 0x40003FFF, you should have used STRB instead.

这篇关于为什么 STR 仅适用于 0x40000000 和 0x40003FFF 之间的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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