我不是真的进入arm汇编语言,但我需要弄清楚这个代码,我希望有人可以解释一下,问候。
.syntax unified
.align 2
.global x
.thumb
.thumb_func
.type x, %function
x:
mov r0, sp
push {lr}
bl .L5
pop {lr}
sub r0,r0,r1
bx lr .L5:
mov r1,sp
bx lr
.size x, .-x
调用此函数时,您期望得到什么结果?
最后,我想知道使用push和pop指令时大括号的目的是什么。
由于
答案 0 :(得分:1)
我认为这些说明,在有意义的地方插入换行符,字面意思意味着:
mov r0, sp # put the value of the stack pointer in the register r0
push {lr} # push the value in the link register on to the stack
bl .L5 # put the value of the next instruction in the link register
# and then branch to code at label .L5
pop {lr} # pop the top stack value into the link register
sub r0,r0,r1 # subtract the value in register r1 from the value in register r0
# and put the difference in register r0
bx lr # branch to the address in the link register and exchange
# instruction set.
.L5: # Just a label.
mov r1,sp # put the value of the stack pointer in the register r1
... [assuming more stuff and a return to the caller]
所以它看起来像:在你的函数中,调用另一个函数。当其他函数返回时,更新r0的值并从函数返回。
答案 1 :(得分:1)
此代码计算推送lr
寄存器的Thumb函数调用所需的堆栈空间量。您可以从C
代码中调用它,例如
int function_call_stack_requirement = x();