.model small
.stack 64
.code
label1:
;some instruction
label2:
;some instruction
jmp label1 ;this will jump to label1
label3:
jmp $ ;this jump where goes if control comes here
jmp $+2 ;what this means
end
plz any body clear this concept about jmp $ and jmp $+2
.stack 64
.code
label1:
;some instruction
label2:
;some instruction
jmp label1 ;this will jump to label1
label3:
jmp $ ;this jump where goes if control comes here
jmp $+2 ;what this means
end
plz any body clear this concept about jmp $ and jmp $+2
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 :)
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
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
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.
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.
"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"
"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"