flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > fasmg examples: error in x64.inc about RIP-addressing

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 473
Location: Belarus
fasmg examples: error in x64.inc about RIP-addressing
Instructions like the following don't compile:


Code:

  include 'x64.inc'

  use64
  org 0x140000000

  mov eax, [0]
  add eax, [0]




The first one may be encoded as

Code:
A1 00 00 00 00 00 00 00 00


The second one as

Code:
40 03 04 25 00 00 00 00


using SIB-form (see Intel 64 manual, vol 2 paragraph 2.2.1.6 RIP-Relative Addressing)
Post 07 May 2017, 18:03
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6356
Location: Kraków, Poland
Have you tried it with fasm 1? It signals the same error here and the macros aim at fasm compatibility. You can only choose the absolute (not RIP-relative) addressing with address size specifier:

Code:
  mov eax, [qword 0]

Post 07 May 2017, 18:56
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 473
Location: Belarus
Thanks, Tomasz. However, I started getting another error

Code:

        add eax, [qword 0]
macro add [21macro store_instruction [24]:
        if (reg or rm_operand.rmand x86.REX_REQUIRED
Processedif (@dest.rm or @src.rmand x86.REX_REQUIRED
Errorsymbol 'rm' is undefined or out of scope.


Post 07 May 2017, 20:14
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6356
Location: Kraków, Poland
In this case it should work with:

Code:
add eax,[dword 0]

But you're right that there is a bug there when "qword" is used.
Post 07 May 2017, 21:30
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6356
Location: Kraków, Poland
I have corrected it, now this works the same as in fasm 1:

Code:
use64
add eax, [dword -1]  ; 67 03 04 25 FF FF FF FF
add eax, [qword -1]  ; 03 04 25 FF FF FF FF

Post 07 May 2017, 21:49
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 473
Location: Belarus
I tried the above instructions with fasm 1, and there's some inconsistency in the output:


Code:

use64
add eax, [dword -1]    ; 67 03 04 25 FF FF FF FF
add eax, [qword -1]    ; 03 04 25 FF FF FF FF
add [dword 0], eax     ; 01 04 25 00 00 00 00
add dword [dword 0], 1 ; 83 04 25 00 00 00 00 01
add [dword 1], eax     ; 01 04 25 01 00 00 00
add dword [dword 1], 1 ; 83 04 25 01 00 00 00 01 



address-size prefix is not added for positive moffs
Post 08 May 2017, 14:32
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6356
Location: Kraków, Poland

zhak wrote:
address-size prefix is not added for positive moffs

The 67h prefix here has an effect equivalent to a choice between sign-extending (when absent) and zero-extending (when present) the 32-bit displacement value into 64-bit address. Therefore the prefix is only needed when 32-bit displacement has the sign bit set but the upper 32 bit need to be zero, like in the case of "[dword -1]" or "[dword 0FFFFFFFFh].
Post 08 May 2017, 14:37
View user's profile Send private message Visit poster's website 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.