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

查看:191
本文介绍了为什么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,恩智浦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.

您还应该认识的一件事是

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天全站免登陆