将数据写入绝对地址 [英] Writing data to absolute address

查看:213
本文介绍了将数据写入绝对地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Cortex-M3微控制器上的汇编器进行测试.我不确定这是否重要,但是您可以.

I'm currently playing around a bit with assembler on a Cortex-M3 microcontroller. 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]

但是似乎我需要引用相对于PC寄存器的VTOR地址.问题是,是否有一种方法可以不引用相对地址,而让它自动执行(这样基本上看起来就像我的方法一样.)

But it seems like I need to reference the VTOR address relative to the PC register. 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).

我正在使用GNU汇编器.

I'm using GNU Assembler.

推荐答案

您需要将目标地址加载到寄存器中.我假设VTOR是内存地址或'C'指针,而__cs3_interrupt_vector_cortex_m是常量.即,您希望将32位常量写入地址.如果是这种情况,

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. Ie, you wish to write a 32bit constant to an address. 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.

ARM/Thumb/Thumb2是加载存储体系结构.您不能在加载和存储指令中使用内存操作数.这样可以简化CPU设计,但是与M68K和x86汇编程序不同.

The ARM/Thumb/Thumb2 is a load-store architecture. 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.

Gnu汇编程序信息页面ldr rX, =val .通常它将转换为以下内容,

The syntax ldr rX, =val is explained in the Gnu assembler info pages. Generally it will convert to the following,

ldr   rX, [pc, #offset]
...
offset: .word val ; your constant is stored here.

pseudo-op .ltorg 告诉汇编器转储文字表;上面代码的 offset 部分.您可以在子例程等之间的任意位置添加.ltorg.

The pseudo-op .ltorg tells the assembler to dump the literal table; the offset portion of code above. You can add an .ltorg anywhere between sub-routines, etc.

您不能使用语法str r4,[=VTOR],因为等于语法只是与ldr一起使用的捷径.例如,

You can not use the syntax str r4,[=VTOR] as the equals syntax is only a short-cut for use with 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.

您可以使用ldr rX,=VTOR语法将地址获取到寄存器.然后,它需要另一个指令,例如str rY, [rX]才能实际写入该地址.

You can use the ldr rX,=VTOR syntax to get the address to a register. It then takes another instruction like str rY, [rX] to actually write to that address.

常量在指令内编码,因此常量范围非常有限,尤其是在 thumb 模式下.我猜您正在使用 thumb2 ,该范围可能更大.

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.

这篇关于将数据写入绝对地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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