cortex M4 Thumb汇编功能地址 [英] cortex M4 Thumb Assembly function address

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

问题描述

我目前正在尝试了解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.

我是否必须将此.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之前必须将代码添加到一个地址上,否则您确实希望汇编程序在定义标签或使用标签时有一个解决方案.

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汇编功能地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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