gpt4 book ai didi

arm - PUSH 和 POP 括号中的寄存器顺序

转载 作者:行者123 更新时间:2023-12-03 08:38:15 27 4
gpt4 key购买 nike

ARM documentation对于 PUSH 和 POP 如下所示

PUSH stores registers on the stack, with the lowest numbered registerusing the lowest memory address and the highest numbered registerusing the highest memory address.

POP loads registers from the stack, with the lowest numbered registerusing the lowest memory address and the highest numbered registerusing the highest memory address.

还有一个tutorial我发现这样说

...the registers in the {} can be specified in any order, but theorder in which they appear on the stack is fixed...

所以根据上面的解释,一个PUSH括号中的寄存器的顺序并不重要。 IE。 PUSH {R0,R1,R2}PUSH {R2,R1,R0}PUSH {R1,R2,R0} 都将导致堆栈中的某些顺序,因为“...最低/最高编号的寄存器(R0/R2)使用最低/最高(堆栈)内存地址...”

  • 这是否意味着单个 PUSH 指令有多个寄存器支架,装配器自动排序插入 Action 在目标代码中,其中 PUSH R2 首先进入堆栈取最高地址,然后是 PUSH R1,最后是 PUSH R0 取最低地址?

  • 因此,如果我想保证 R2 在 LIFO 堆栈中最后压入并首先弹出(即。SP指向R2或R2取最低堆栈地址),我不能在一个 PUSH 括号语句中执行此操作,但只能单独使用 PUSH R0;按 R1;推 R2

最佳答案

你已经很接近了,你需要始终获得TRM(核心的技术引用手册,cortex-m3cortex-m0等)和ARM(该核心指定的架构的架构引用手册armv6-marmv7-m , armv8-m )

.thumb

push {r0,r1,r2}
push {r2,r1,r0}
push {r0}
push {r1}
push {r2}

Disassembly of section .text:

00000000 <.text>:
0: b407 push {r0, r1, r2}
2: b407 push {r0, r1, r2}
4: b401 push {r0}
6: b402 push {r1}
8: b404 push {r2}

从ARM ARM中你可以看到push指令的低8位是寄存器列表/掩码。所以 r0 是位 0,r1 是位 1,依此类推。所以b407中的7表示r0,r1,r2这三个寄存器。该逻辑在机器代码而不是汇编语言上运行,机器代码从位 7 转到位 0(如果设置),然后压入该寄存器。汇编器所做的只是创建机器代码,它不会创建额外的指令或类似的东西。

如果您希望它们以不同的顺序排列,那么您必须用汇编语言将它们编写在单独的指令中。

The registers are stored in sequence, the lowest-numbered register to the lowest memory address (start_address), through to the highest-numbered register to the highest memory address (end_address)

The start_address is the value of the SP minus 4 times the number of registers to be stored.

Subsequent addresses are formed by incrementing the previous address by four. One address is produced for each register that is specified in .

The end_address value is four less than the original value of SP.The SP register is decremented by four times the numbers of registers in.

关于arm - PUSH 和 POP 括号中的寄存器顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63304428/

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