[英]Writing data to absolute address
I'm currently playing around a bit with assembler on a Cortex-M3 microcontroller.我目前正在 Cortex-M3 微控制器上使用汇编器。 I'm not sure if this is important, but here you go.
我不确定这是否重要,但是你去吧。
I need to write a value into to a certain address in memory.我需要将一个值写入内存中的某个地址。 Here is what I tried:
这是我尝试过的:
LDR R4, =__cs3_interrupt_vector_cortex_m
STR R4, [=VTOR]
But it seems like I need to reference the VTOR address relative to the PC register.但似乎我需要引用相对于 PC 寄存器的 VTOR 地址。 The question is if there is a way to not reference the address relativ and let this do automatically (so that it would basically look like my approach).
问题是是否有办法不引用地址相对并让它自动执行(这样它基本上看起来像我的方法)。
I'm using GNU Assembler.我正在使用 GNU 汇编程序。
You need to load the destination address to a register.您需要将目标地址加载到寄存器中。 I assume that
VTOR
is a memory address or 'C' pointer and __cs3_interrupt_vector_cortex_m
is a constant.我假设
VTOR
是一个内存地址或“C”指针,而__cs3_interrupt_vector_cortex_m
是一个常数。 Ie, you wish to write a 32bit constant to an address.即,您希望将 32 位常量写入地址。 If this is the case then,
如果是这样的话,
; Get value __cs3_interrupt_vector_cortex_m to r4
ldr r4, =__cs3_interrupt_vector_cortex_m
ldr r5, =VTOR ; address 'VTOR' to r5.
str r4, [r5] ; write the constant to 'VTOR' address.
The ARM/Thumb/Thumb2 is a load-store architecture. ARM/Thumb/Thumb2 是一种加载存储架构。 You can not use memory operands in the load and store instructions.
您不能在加载和存储指令中使用内存操作数。 This simplifies the CPU design, but is different from M68K and x86 assembler.
这简化了 CPU 设计,但与 M68K 和 x86 汇编器不同。
The syntax ldr rX, =val
is explained in the Gnu assembler info pages .语法
ldr rX, =val
在Gnu 汇编程序信息页中进行了解释。 Generally it will convert to the following,一般会转换成下面这样,
ldr rX, [pc, #offset]
...
offset: .word val ; your constant is stored here.
The pseudo-op .ltorg
tells the assembler to dump the literal table;伪操作
.ltorg
告诉汇编器转储文字表; the offset portion of code above.上面代码的偏移部分。 You can add an
.ltorg
anywhere between sub-routines, etc.您可以在子例程等之间的任何位置添加
.ltorg
。
You can not use the syntax str r4,[=VTOR]
as the equals syntax is only a short-cut for use with ldr
.您不能使用语法
str r4,[=VTOR]
因为equals语法只是与ldr
一起使用的捷径。 For example,例如,
ldr rX,=7 ; is really 'mov rx,#7' in all modes.
ldr rX,=0xff ; is 'mov rx,#0xff' for ARM and '[pc,#offset]' for thumb.
ldr rx,=0x12345678 ; will use the [pc, #offset] for all modes.
You can use the ldr rX,=VTOR
syntax to get the address to a register.您可以使用
ldr rX,=VTOR
语法来获取寄存器的地址。 It then takes another instruction like str rY, [rX]
to actually write to that address.然后它需要像
str rY, [rX]
这样的另一条指令来实际写入该地址。
Constants are encoded inside an instruction so the constant range is very limited especially in thumb mode.常量在指令中编码,因此常量范围非常有限,尤其是在拇指模式下。 I guess you are using thumb2 which may have more range.
我猜你正在使用可能有更大范围的拇指2 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.