cortex M4 Thumb Assembly 函数地址 [英] cortex M4 Thumb Assembly function address

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

问题描述

我目前正在尝试了解 Cortex-M 内核的 ARM 程序集.

I'm currently trying to understand ARM assembly for Cortex-M cores.

我知道处于 Thumb 模式(这是内核支持的唯一模式)的函数是通过它们的地址调用的,并且地址的 LSB 为高表示目标是 Thumb 代码.

I know that functions that are in Thumb mode (which is the only mode the core supports) are called by their address and the LSB of the address is high to indicate that the destination is Thumb code.

在汇编中,我在函数Reset_Handler"前面写了以下内容来告诉汇编器标签处的数据是可执行的/函数:

In assembly I write following in front of the function "Reset_Handler" to tell the assembler that the data at the label is executable/a function:

  .type  Reset_Handler, %function
  Reset_Handler: 
  MOV R0, R0 # just do something

如果我现在加载标签的地址

If I now load the address of the label

  LDR R0, =Reset_Handler

设置 R0 的 LSB.

the LSB of R0 is set.

我是否必须将此 .type 指令放在每个我想用作间接调用函数的标签之前?

Do I have to put this .type directive in front of every label I want to use as a function with indirect calls?

或者有没有办法让汇编器自动决定正确的地址?

Or is there a way to let the assembler automatically decide the correct address?

如果我想把函数的代码复制到RAM并加载这个函数的地址,我必须自己清除LSB才能得到数据所在的真实"地址,对吗?

If I want to copy the code of the function to RAM and load the address of this function, I have to clear the LSB myself to get the "real" address where the data is located, am I right?

在这种情况下是否需要 .type 指令?我知道一旦我想将地址放入向量表中,这是必要的,因为这需要设置 LSB.

Is the .type directive necessary in this case? I know that it is necessary as soon as I want to put the address in the vector table as this requires the LSB to be set.

推荐答案

嗯,有两种类型的地址(标签).一种类型是您要调用的地址,函数入口点的地址,并且 bx 或 pop 需要设置 lsbit.另一个是数据项的地址,字符串的开头,数组的开头等等,并且不希望 lsbit 损坏,因为这会导致对齐错误.因此,除非您想在使用 bx 之前在地址上添加 OR 的代码,否则您真的希望汇编程序在您定义标签或使用标签时有一个解决方案.

Well there are two types of addresses (labels). One type is an address you want to call, the address of the entry point of a function and for thumb the bx or pop needs the lsbit set. The other is the address for a data item, the beginning of a string, the beginning of an array, whatever, and that does not want the lsbit corrupt as that would cause an alignment fault. So unless you want to have to add code to OR one onto an address before using bx you really want the assembler to have a solution either when you define the label or when you use the label.

因此,对于 gnu 汇编程序,您需要在标签之前使用 .thumb_func(可能还有其他方法),对于您的汇编程序,您似乎需要汇编程序所需的内容.

So for gnu assembler you need .thumb_func before the label (and probably other ways to do it), for your assembler it appears you need what your assembler requires.

这篇关于cortex M4 Thumb Assembly 函数地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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