For a Visual C++ project I'm working on, I need to ensure that the jumps in the inline assembly code I'm writing will always be relative, since the code will be self modyfying, so the same code may be excecuted from muliple memory locations. According to the manual I found it should be something like this:

jmp SHORT (signed jump bytes)

However, this just gives me a bunch of syntax errors, so does anyone know the correct way? I know the assembler would probobly use short jumps automatically even if I didn't tell it to as a speed optimization, but I'd rather not be at the mercy of the compiler on this, since if it doesn't happen the code will crash and burn. Oh, and if there is no way to force a short jump, is there a way I can insert the raw bits for the opcode in with the rest of my asm code block prior to runtime. Manually inserting it at runtime would in my case be worse then depending on the grace of the assembler, but I know I could do it as a last resort.
Posted on 2004-11-16 14:27:43 by Xzyx987X
All direct jumps are relative, whether they're short or not. If you want to be sure they're short, maybe you could use db 0ebh, Something?
Posted on 2004-11-16 14:48:36 by Sephiroth3
I know they're supposed to be relative, but when I tried using a relative value like say je 0x10, the assembler compiled it as a jump to the next opcode no matter what. It doesn't seem to like allowing jumps that aren't relative to labels.
Posted on 2004-11-16 15:17:36 by Xzyx987X
db doesn't seem to work. I used db 0x8417 for je 0x17, but got a syntax error complaining the db wasn't an opcode. Is it just me, or does it seem really stuipid that microsoft's assembler would make such an obvious ommision as far as fully supporting the x86 instruction set goes. I mean, I know self-modyfing code isn't used a whole lot, but surely they could've anticipated the need for this sort of thing.
Posted on 2004-11-16 15:48:56 by Xzyx987X
Two things:
1st, the db opcode is expected to be followed by a byte value, i.e. less than 0xFF. your compiler complained correctly when you tried to initialize a byte with 0x8417.
2nd, the code for je is 0x74. None of the conditional jumps have the 0x84 coding. That 0x84 coding is for the TEST of an 8-bit register.

The following should work as in-line code if you want to do a short jump of 23 bytes (0x17) when the Z flag is set:

db 0x74,0x17

Raymond
Posted on 2004-11-16 20:40:35 by Raymond
Two things:
1st, the db opcode is expected to be followed by a byte value, i.e. less than 0xFF. your compiler complained correctly when you tried to initialize a byte with 0x8417.
2nd, the code for je is 0x74. None of the conditional jumps have the 0x84 coding. That 0x84 coding is for the TEST of an 8-bit register.
Sorry, that was a typo :P.
The following should work as in-line code if you want to do a short jump of 23 bytes (0x17) when the Z flag is set:

db 0x74,0x17
Should, but doesn't. Visual C++ gave me: "error C2400: inline assembler syntax error in 'opcode'; found 'constant'". I'm beginning to think the Visual C++'s inline assembler isn't all that great... Any other ideas?
Posted on 2004-11-16 22:03:59 by Xzyx987X