JMP vs. CALL in 8086 assembly

偶尔善良 提交于 2019-12-12 05:37:38

问题


Can I use JMP and RET to jump back from a label as you would with CALL and RET?


回答1:


When you use CALL the current value of the instruction pointer is saved on the stack...when the corresponding RET executes, it takes the address from the stack and jumps there. If you just JMP without saving the current address on the stack the corresponding RET will, unsurprisingly, not find a correct address where it expects one. It will probably find some data, nevertheless, it will try to jump to the address represented by those bits. On any decent processor, this will result in some form on violation.

You can jump to a procedure and return with a RET only if you mimic what the CALL instruction does.




回答2:


No. JMP changes the instruction pointer. CALL pushes the current IP onto the stack and updates the instruction pointer.

If you use a RET with a JMP you are going to return to some unknown location based on what happens to be on the stack at that moment.




回答3:


A better answer if you want to use JMP to replace CALL, but still use RET or as a replacement for RET also:

    PUSH WORD CS:Call_Return
    JMP My_Method
Call_Return:
    ... (cont)

My_Method:
    ...(some code)
    RET

Or

My_Method:
    ...(some code)
    POP DX
    JMP DX

This just proves it is possible to do the same thing many different ways. This assumes 16-bit addressing (real mode) which does make a difference in this case. In 32-bit/64-bit addressing modes you will need to change the push, pop, and JMP commands accordingly.




回答4:


Maybe if you used something like this :

MOV BX,IP
ADD BX,10  ;If I am not mistaken mov=3bytes,add=3bytes jmp=3 bytes,push=1 byte
PUSH BX
JMP

and then :

RET


来源:https://stackoverflow.com/questions/28964692/jmp-vs-call-in-8086-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!