JMP vs CALL in assembly 8086

Can I use JMP and RET to return from the label, as would be the case with CALL and RET ?

0
assembly x86 x86-16
source share
4 answers

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

If you use RET with JMP , you will return to an unknown location depending on what is happening on the stack at that moment.

+3
source share

When you use CALL, the current value of the instruction pointer is stored on the stack ... when the corresponding RET is executed, it takes the address from the stack and jumps there. If you are just JMP, without storing the current address on the stack corresponding to RET, it is not surprising that you will not find the correct address where it expects it. He will probably find some data, however, he will try to go to the address represented by these bits. On any decent processor, this will lead to some form of violation.

You can go to the procedure and return with RET only if you mimic what the CALL statement does.

+3
source share

The best answer is if you want to use JMP to replace CALL , but still use RET or as a replacement for RET as well:

  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 only proves that the same thing can be done in many different ways. This assumes 16-bit addressing (real mode), which makes a difference in this case. In 32-bit / 64-bit addressing modes, you will need to change the push, pop, and JMP commands accordingly.

+2
source share

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 
+1
source share

All Articles