flat assembler
Message board for the users of flat assembler.

Index > Main > Encoding 64-bit CALL's and JMP's

Author
Thread Post new topic Reply to topic
iseyler



Joined: 17 Jul 2008
Posts: 3
Location: Kitchener, Ontario
iseyler 02 Jul 2009, 20:46
Hi everyone,

In the Intel manual it talks about a 64-bit absolute indirect jump: FF /4 - JMP r/m64 - Jump near, absolute indirect, RIP = 64-Bit offset from register or memory.

How can I use this opcode? I get an "error: value out of range." error when compiling the code below.

Code:
USE64
ORG 0x0000000000100000

kernel_start:
   call 0x1234567890abcdef
    


Thanks,
-Ian

_________________
BareMetal OS - http://www.returninfinity.com/bare-metal-os
Mono-tasking 64-bit OS for x86-64 based computers written entirely in Assembly
Post 02 Jul 2009, 20:46
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 02 Jul 2009, 21:04
I quess that "call" is not jump ("jmp"). Also, "indirect" means that address is stored in memory at address that is given by instruction argument, eg. "jmp [12345678AABBCCDDh]" instead of "jmp 12345678AABBCCDDh".
Post 02 Jul 2009, 21:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Jul 2009, 21:36
iseyler, that doesn't mean the address of the m64 operand can be a 64-bit sized address.

You'll have to use this:
Code:
USE64
ORG 0x0000000000100000

kernel_start:
        mov  rax, 0x1234567890abcdef
        jmp  rax           ; Encoded as FF E0
        jmp near [pointer] ; Encoded as FF 25 [03 00 00 00] (RIP-relative address)
        int3
        int3
        int3
pointer dq 0x1234567890abcdef
    


In the context of the Intel's documentation, m64 means that it is the memory pointer which will be 64 bits wide, not that the 64-bit target will be encoded in the instruction.
Post 02 Jul 2009, 21:36
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 03 Jul 2009, 05:55
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 03 Jul 2009, 05:55
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 03 Jul 2009, 11:57
Yes, it is. Address of variable 'pointer' is RIP-relative.
Post 03 Jul 2009, 11:57
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 03 Jul 2009, 12:56
This is a diagram:

Code:
     RELATIVE OFFSET                                   ABSOLUTE 64-BIT ADDRESS
call----------------->qword value at address specified------------------------->function address    
Post 03 Jul 2009, 12:56
View user's profile Send private message Reply with quote
iseyler



Joined: 17 Jul 2008
Posts: 3
Location: Kitchener, Ontario
iseyler 03 Jul 2009, 15:16
Thanks for the info!

I'll go ahead with the "jmp near [pointer]" method as I don't want to overwrite a register.

Thanks again,
-Ian
Post 03 Jul 2009, 15:16
View user's profile Send private message Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 03 Jul 2009, 15:38
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 03 Jul 2009, 15:38
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Jul 2009, 15:45
Dear asmcoder,
Code:
; pseudo-code of JMP
mov temp, qword [RIP+3] ; [pointer] loaded into temp ; This is the RIP-relative part
mov RIP, temp    
Post 03 Jul 2009, 15:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.