大会'call'vs'jmp' [英] Assembly 'call' vs 'jmp'
问题描述
我被告知尝试使用"jmp"而不是"call",但是"jmp"并不喜欢我..当我跳时它不会返回(因此它永远不会退出,也不是快乐的日子),但是会调用返回并照常退出.
I got told to try and use 'jmp rather than 'call', but 'jmp' is not liking me .. when I jump it doesn't return (so it never exits and not happy days ), but calling returns and exits as normal.
我很高兴使用'call',但是实际上我有理由尝试克服'jmp'吗?
I am happy using 'call' but is there actually a reason I should try and overcome 'jmp' ?
这个简单的代码仅显示了当我jmp
时它从不返回并退出.
This simple code just shows if when I jmp
it never returns and exits.
_start:
jmp _Print
jmp _Exit
ret
_Exit:
; normal exit
ret
_Print
; print something
ret
还..如果一切发生变化,我将在Linux终端中运行所有这些操作.
also .. I'm running this all in a Linux terminal if that changes anything.
推荐答案
首先,jmp
只是简单地跳转"到您为其赋予的标签(这是程序指令存储在其中的内存地址) call
存储在call
指令下面的位置(在call
指令之下),在jmp
处返回到标签,然后在ret
指令中,在ret
指令中返回jmp
回到所存储的位置(如上所述,在调用说明下方).如您所见,那里有些不同.恕我直言,我相信简单地使用call
函数就可以了,因为这是c ++编译器对函数的处理,但是如果必须jmp
,那么就可以了,只需确保push
返回位置或创建另一个标签,返回到执行完一些代码后返回的位置.
Well, first of all, jmp
simply 'jumps' to the label that you give to it (which is a memory address as program instructions are stored in memory) while call
stores the location where it will return (below the call
instruction) in the stack, jmp
to the label, and then at the ret
instruction, jmp
back to what location was stored (as said above, below the call instruction). A bit of a difference there as you can see. IMHO, i believe it is fine to simply call
functions, as that is what the c++ compiler does with functions, but if you must jmp
, then alright then, just make sure to push
the return location or create another label to return to once done executing some code.
以下是完成后跳转到其他标签的示例:
Here is an example of jumping to other label when done:
_start:
jmp _Print;
_start_label:
jmp _Exit;
_Exit:
; exit stuff goes here
ret;
_Print:
;print stuff goes here
jmp _start_label;
或者您可以只使用call:)
or you could just use call :)
这篇关于大会'call'vs'jmp'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!