从跳转返回到主 [英] Return from jump to main

查看:35
本文介绍了从跳转返回到主的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

_main:
    .
    ..
    ...
    call label_1 
    operation_a
    ...
    ..
    .

"call" 将label_1的地址推入堆栈,并执行它的代码.为了继续执行operation_a"等,label_1"必须包含一个ret",它弹出label_1的地址并继续执行operation_a"等等.

"call" pushes the address of label_1 into the stack, and executes it's code. In order to keep executing "operation_a" and so on, "label_1" must contain a "ret" which pops the address of label_1 and continues with "operation_a" and so on.

在我的问题中

_main:
    .
    ..
    ...
    je label_1 
    operation_a
    ...
    ..
    .

在这种情况下,je"跳转到 label_1,因此我不能将ret"添加到label_1"中的指令集,然后...

In this case, "je" makes a jump to label_1, therefore I can't add "ret" to the set of instructions in "label_1", then...

我怎样才能从那个跳转回到主代码?是否有调用"标签的条件跳转?

How can I come back from that jump to the main code? is there a conditional jump that "calls" a label?

有朋友提到我可以在label_1的末尾加一个jmp aux_label",然后在main函数中加那个aux_label",但是如果我碰巧做了很多je",我最终会创建很多标签.

A friend mentioned that I can add a "jmp aux_label" at the end of label_1, and add that "aux_label" in the main function , but if I happen to do many "je", I would end up creating many labels.

推荐答案

没有条件调用这样的东西.但是您可以将调用与条件跳转结合起来:

There's no such thing as a conditional call. But you can combine a call with a conditional jump:

  ...
  jne no_call
  call label_1 
no_call:
  operation_a
  ...

这样,如果不满足相等条件,则跳过call 命令,不会发生调用.如果满足相等条件,JNE 什么都不做,你做一个 call 然后最终 ret 从它到 operation_a>.

This way, if the equality condition is not met, you jump over the call command and no call takes place. If the equality condition is met, JNE does nothing, you do a call and then eventually ret from it to operation_a.

no_call 不是操作,而是标签.所以no_call的地址和operation_a的地址是一样的,以防万一.

no_call is not an operation, it's a label. So the address of no_call and the address of operation_a is the same thing, in case that was unclear.

JNE 到标签几行"的技巧与汇编中的 if() 语句一样接近.

The "JNE to a label a few lines down" trick is as close as it gets to an if() statement in assembly.

在汇编代码中创建许多标签是一个不幸的事实.:)

Creating many labels is an unfortunate fact of life when coding in assembly. :)

这篇关于从跳转返回到主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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