Hi
What are the differences between call and jump instruction?
Posted on 2006-12-31 06:30:26 by sawer
Hi sawer,

They both jump to a given location, but there is a difference:
Call puts a return address on the stack, while jmp doesn't.
A Ret instrunction pops the return from the stack. Execution is continued the line after the Call.

This illustrates it:

;Jmp to MyProc, but save the return address on the stack.
call MyProc

;After a normal return from MyProc, execution is continued here
...

MyProc Proc
    Ret  ;Pop the return address from the stack, and continue there.
MyProc Endp


Suppose you would Jmp to MyProc, instead of Calling it: When your program reaches the Ret instruction, it will try to pop the return address from the stack. But you didn't save it there! So, your program will crash.

Friendly regards,
mdevries.
Posted on 2006-12-31 07:15:21 by mdevries
ok.
Thank you
Posted on 2006-12-31 07:33:57 by sawer
More importantly, knowing this, you can write the return address from WITHIN a proc, so you can return to N other places ! and other fun stuff :)
Just pop once too often (return address of proc) then push (address of place to go to) then do your ret, and blammo - amusing :)
Posted on 2006-12-31 09:07:27 by Homer
Hi,

More importantly, knowing this, you can write the return address from
WITHIN a proc, so you can return to N other places ! and other fun stuff
Just pop once too often (return address of proc) then push (address of
place to go to) then do your ret


Be aware of the stackframe.

Suppose we have a procedure with 2 arguments, and we are not using a stackframe. Looking at the stack from within our procedure, the stack looks like this:

SP+4:    Arg 1
SP+2:    Arg 2
SP:      Return address


So popping once will fetch the return address.
Pushing a new value will install the new return address.
   
But if there were a stackframe, the stack would look like this:

BP+6:    Arg 1
BP+4:    Arg 2
BP+2:    Return address
BP/SP:  Old BP


Popping once will fetch the old BP.
Pushing a new value will only overrride the old BP.
So, you will not be returning to a different location.

Friendly regards,
mdevries.
Posted on 2006-12-31 10:22:16 by mdevries
Thank you for your answers.
I am studying 8086 instruction set.I want to ask you one more question.
What are the differnces between rep and loop?
Both of them use cx and make loop.
Posted on 2006-12-31 11:13:52 by sawer
Are there not compiling differences too.
One gets repeated throughout the code and the other only gets written once and has references to it kinda thing.
...can't remember which asm commands it was tho...
Posted on 2006-12-31 11:47:56 by eek
loop is a compiler macro which implements a rep (operation).
There is no such opcode, but there is such operation ;)
Posted on 2006-12-31 12:35:40 by Homer
Homer,

There's really an opcode called loop. Seriously speaking.

It's usage is

loop label

the only disadvantage about the opcode is that it is slow and that you can only jump within -127 to 128 or something that.

PS: Still trying to find time to play with your matrix codes. Really sorry.
Posted on 2006-12-31 13:42:10 by roticv
Though I mostly rely on the "Intel 80386 Programmers Reference Manual" for my information, AFAIK, both REP (along with REPE/REPZ/REPNE/REPNZ) and LOOP (along with LOOPE/LOOPZ/LOOPNE/LOOPNZ) have opcodes related to their operation on the x86 architecture.
Posted on 2006-12-31 13:49:05 by SpooK
Strictly speaking, REP is not an opcode - it is an opcode prefix. It is combined with string instructions to create repetitive versions of the basic string instruction.

The prefix nature is emphasized when you write the two so-called "opcodes" on the same line, as in

REP MOVSB
Posted on 2007-01-01 16:59:32 by tenkey