Question

The first form of JMP in x86-64 is:

Opcode    Instruction  Description
EB cb     JMP rel8     Jump short, RIP = RIP + 8-bit displacement sign

So for example JMP rel8=-2 is eb fe. fe is a one byte signed 2s-compliment -2.

How do I express this rel8 immediate in Intel syntax?

I tried the following:

test.s:

.intel_syntax noprefix
.global _start
_start:
    jmp -2

Compile with:

$ gcc -nostdlib test.s
$ objdump -d -M intel

But I get:

   e9 00 00 00 00           jmp    5 <_start+0x5>

Not eb fe as desired.

(More generally, where is Intel syntax documented? I couldn't find anything in the Intel manual about it. The Intel manual explains how to encode operands, but it doesn't give the syntax of the assembly language.)

Update:

Solution is:

.intel_syntax noprefix
.global _start
_start:
    jmp .

. must represent address of current instruction. Assembling it and disassembling gives:

4000d4: eb fe      jmp    4000d4 <_start>

eb fe as desired. RIP-relative addressing is in terms of the next instruction, so the assembler must adjust for the size of the current instruction for you.

Was it helpful?

Solution

(G)AS apparently uses . to denote the current address (the address of the current instruction), unlike most other assemblers.

There is a tiny page documenting it here in the documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top