V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ciichen
V2EX  ›  嵌入式开发

请教 ARM LDM 指令读数据到 PC 寄存器的一个问题

  •  
  •   ciichen · 2021-06-08 19:22:40 +08:00 · 974 次点击
    这是一个创建于 1024 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在学 ARM 汇编,看到 LDM 指令的时候有个问题看不懂了。

    Loading to the PC
    A load to the PC causes a branch to the instruction at the address loaded.

    In ARMv4, bits[1:0] of the address loaded must be 0b00.

    In ARMv5T and above:

    bits[1:0] must not be 0b10

    • if bit[0] is 1, execution continues in Thumb state
    • if bit[0] is 0, execution continues in ARM state.

    这是ARM官方对 LDM 指令读数据 PC 寄存器的描述。

    为什么 bit[0] 置 1 之后,接下来就进到 Thumb 模式继续执行了呢。Tumb 指令两字节对齐,bit[0] 应该也是 0 吧。

    3 条回复    2021-06-08 23:12:20 +08:00
    churchmice
        1
    churchmice  
       2021-06-08 19:52:31 +08:00
    我来给你解释一下
    不论如何地址都是需要 16bit 对齐的,所以硬件在去 memory load 代码的时候是强制把 bit[0]干成 0 的,也就是说 bit[0]在取值的时候就没有意义了,但是可以包含其他的信息,这个信息就是接下来 cpu 处于什么状态

    00: ARM state
    01: thumb state
    10: bit[0] ==0 ,代表是 ARM state, 要求地址 32 对齐,所以这个是非法的 encoding
    11: thumb state
    churchmice
        2
    churchmice  
       2021-06-08 19:57:23 +08:00
    当然你可以跟我争辩 10 的 encoding 也可以表明是 arm state,硬件在做的时候直接忽略低 2bit 就可以了
    但是你这样做会增加硬件复杂性,虽然只是一丢丢,但是会影响到 cpu 频率的提升,所以硬件是不会做这个额外的事情的
    ciichen
        3
    ciichen  
    OP
       2021-06-08 23:12:20 +08:00 via Android
    @churchmice 多谢!现在知道了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:03 · PVG 06:03 · LAX 15:03 · JFK 18:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.