.model small
.stack 64
          ;some instruction

          ;some instruction
          jmp label1        ;this will jump to label1
          jmp $              ;this jump where goes if control comes here
          jmp $+2          ;what this means


plz any body clear this concept about jmp $ and jmp $+2

Posted on 2006-05-21 03:20:59 by sihotaamarpal

The $ symbol means "this address".
Look at this:

SomeLabel: jmp $

In this example, $=SomeLabel.
The jump will create an infinite loop.

How can we make this useful?
Here's an example, known as 'the delta method".

call $+5
pop eax

The CALL instruction is 5 bytes long.
That means we're 'calling the pop eax instruction'.
Since CALL pushes the return address onto the Stack, the address of the POP EAX is now on the stack.
When the POP is executed, eax now contains the address of the POP EAX instruction - our code just figured out where in memory it is executing ;)

So - $ means "the beginning of the instruction in which the $ appears".

Have a nice day :)
Posted on 2006-05-21 03:54:06 by Homer
hi homer

jmp $ ;means calling this address continously

but if code is this

?? jmp $+2??  ;means jump(this address+2 i.e offset (where jmp $+2)+2)
;i.e jmp to mov ah,05 if mov inst at this offset+2
?? mov ah,05
?? mov al,06
am i right homer

but if i write
?? jmp $+1
mov ah,05
mov al,06

plz explain where it goes
Posted on 2006-05-21 04:36:57 by sihotaamarpal
There's lots of ways to encode a jmp instruction, but I'm sure most compilers will select the 'short relative' encoding for $+2, which is "EB 00" in hex, and obviously, is two bytes in length.
So, back to your original question, and assuming that the compiler spits out what I suggested, the jmp opcode is 2 bytes, so $+2 is the very NEXT opcode after the jmp, basically we just did an expensive NOP.
Posted on 2006-05-21 08:49:37 by Homer
"JMP $" simply hangs the execution (a.k.a 'infinite loop').

"JMP $+2" (using the short form) is often used to clear the prefetch queue inside the CPU. You really shouldn't be doing this unless you know what you're doing (for example: OS development), because it hurts the performance greatly. Other than that, it's exactly like Homer said: an "expensive NOP"
Posted on 2006-05-21 09:44:01 by ti_mo_n