gpt4 book ai didi

assembly - ARM汇编中的函数地址有一个字节的偏移量?

转载 作者:行者123 更新时间:2023-12-04 01:55:10 25 4
gpt4 key购买 nike

例如,我有以下由 objdump 获得的汇编代码。 f() 的地址是 080001d4 。但是 printf("%x", f) 输出 080001d5f() 可以通过 (*((int (*)())080001d5))()(*((int (*)())080001d4))() 完成。

为什么函数地址有一个字节的偏移量?

080001d4 <f>:
80001d4: 2000 movs r0, #0
80001d6: 4770 bx lr

最佳答案

ARM 有两种指令模式,地址的最低有效位用于指示给定函数使用哪种模式。 Thumb 模式的奇数地址,ARM 模式的偶数地址。

即使您使用 -marm 开关重新编译它,地址也会是。

[1] 中的第 A4.1.1 节“在 Thumb 状态和 ARM 状态之间切换”陈述如下:

A processor in Thumb state can enter ARM state by executing any of the following instructions: BX , BLX , or an LDR or LDM that loads the PC.

....

The target instruction set is either encoded directly in the instruction (for the immediate offset version of BLX ), or is held as bit[0] of an interworking address.



[1] ARM® 架构引用手册:ARMv7-A 和 ARMv7-R 版。 ARM,2014 年。DDI 0406C.c。 [在线的]。可用: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html 。 [2019 年 8 月 26 日访问]。

关于assembly - ARM汇编中的函数地址有一个字节的偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37004954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com