Re: x86 VM
- Posted by Bernie <xotron at PCOM.NET> Nov 11, 2000
- 463 views
On Sat, 11 Nov 2000 12:50:02 -0500, Darth Maul, aka Matt <uglyfish87 at HOTMAIL.COM> wrote: >Then would you mind explaining why NASM generates code for a relative jump( >near)? > >Here's some assembly code: > >Jmp lbl >Jmp short lbl >lbl: > >And here's NDISASM's output: > >[WINDOWS] C:\EUPHORIA>ndisasm test >00000000 E90200 jmp 0x5 >00000003 EB00 jmp short 0x5 First debug can not be told to use a certain instruction so it can not be used for comparison. The above code really would not be logical because the second instruction wouldn't be executed, but I know what you are getting at in your example. The first instruction uses a E9 jmp RELATIVE 16 and the 16 bit address following E9 is the NUMBER of bytes to junp. Because 0200 is BYTE SWAPPED so it represents 2 BYTES ( 0002 ). The PROGRAM COUNTER ALWAYS point to the next INSTRUCTION to be EXECUTED which is ADDRESS 0003. The 2 byte RELATIVE offset is ADDED to the PROGRAM COUNTER which advances to the NEXT instruction to be executed. The second instruction EB jmp RELATIVE 8 will ADD a RELATIVE offset of 00 to the PROGRAM COUNTER because REMEMBER it is already pointing to ADDRESS 5. Take a look at the pete's ASM.E because it ENCODES instructions and it might help to write your code. Bernie be ADDRESS 5. In the second instr