How do I know whether MASM encodes my JMP instruction using a relative or absolute offset?

感情迁移 提交于 2019-12-12 04:20:56

问题


How do I know whether MASM encodes my JMP instruction using a relative or absolute offset?

I know that x86 provides JMP opcodes for relative and absolute offsets.

I want to be certain that my jumps are relative, however I cannot find any proper MASM documentation telling me whether JMP @label actually translates into a relative jump.

Please, if possible, give a link to documentation in the answer.


For the opposite issue: See How to code a far absolute JMP/CALL instruction in MASM? if you're trying to get MASM to emit a direct absolute far jmp


回答1:


The only machine encodings for direct near jmps use relative displacements, not absolute. See also the x86 tag wiki for more links to docs / manuals, including the official MASM manual. I don't think there's any point wading through it for this issue, though.


There is no near-jmp that takes an immediate absolute displacement, so there's no risk of an assembler ever using a non-PIC branch unexpectedly.

An absolute near jump would require the address in a register or memory operand, so MASM can't just assemble jmp target into

section .rodata
pointer_to_target dq target          ; or dd for a 32bit pointer

section .text
jmp    [pointer_to_target]

because that would be ridiculous. IDK if you'd ever find documentation stating that this specific piece of insanity is specifically impossible.

The only way I could imagine an assembler doing anything like this for you is if there was some kind of "Huge code model" where all jump targets were referenced with 64 bit pointers instead of 32 bit relative displacements.

But AFAIK, if you want to do that, you have to do it yourself in all existing assemblers.

Documentation gets bloated enough without mentioning every weird thing that a program doesn't do, so I wouldn't expect to find anything specific about this. This is probably one of those things that's assumed to be obvious and goes without saying. (Or that the syntax matches what Intel uses in their instruction reference manual.)


As Jester says, you won't get a far jump without asking for it, so there's no risk of any assembler using the JMP ptr16:32 encoding (EA imm16(segment) imm32(offset)) for a normal jmp.



来源:https://stackoverflow.com/questions/38434627/how-do-i-know-whether-masm-encodes-my-jmp-instruction-using-a-relative-or-absolu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!