flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > cmp rax, 0xffffffff

Author
Thread Post new topic Reply to topic
RIxRIpt



Joined: 18 Apr 2013
Posts: 50
RIxRIpt 10 Jun 2015, 20:40
Code:
flat assembler  version 1.71.39  (1048576 kilobytes memory)
myfilename.asm [321]:
                                cmp rax, 0xffffffff
error: value out of range.
    

Why?
It's possible to assemble this in x64 dbg and the hexcode is:
Code:
48 3D FF FF FF FF        | cmp rax,FFFFFFFF
    

Bug?

Update: stepping the instruction above in the debugger results in ZF=0 when RAX=00000000FFFFFFFF.
What's wrong with it?

_________________
Привет =3
Admins, please activate my account "RIscRIpt"
Post 10 Jun 2015, 20:40
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 10 Jun 2015, 23:39
RIxRIpt
Quote:
It's possible to assemble this in x64 dbg and the hexcode is

x64dbg assembles this incorrectly. The immediate is sign-extended and the comparison is therefore made with 0xffffffffffffffff, not with 0xffffffff.

_________________
Faith is a superposition of knowledge and fallacy
Post 10 Jun 2015, 23:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 00:56
Values between -2^31 (0xffffffff80000000, stored as 0x80000000) and +2^31-1 (0x000000007fffffff, stored as 0x7fffffff) are encodable. Your number is 2^32-1 (0x00000000ffffffff) and cannot be encoded, because, as l_inc says, sign extending a stored value of 0xffffffff gives an absolute value 2^64-1 (0xffffffffffffffff).
Post 11 Jun 2015, 00:56
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 11 Jun 2015, 08:44
When you use explicitly declaration you will get a more detailed error message. Wink

Code:
cmp rax, qword 0xffffffff    


throws

"Error: not encodable with long immediate"

instead of just

"Error: value out of range"

It is possible to use

Code:
mov rbx,0xffffffff
cmp rax,rbx    


instead.
Post 11 Jun 2015, 08:44
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 08:48
shutdownall wrote:
When you use explicitly declaration you will get a more detailed error message. Wink

Code:
cmp rax, qword 0xffffffff    


throws

"Error: not encodable with long immediate"

instead of just

"Error: value out of range".
Well actually that error is for all values:
Code:
cmp rax,qword 0
error: not encodable with long immediate.    
Post 11 Jun 2015, 08:48
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 11 Jun 2015, 08:50
revolution wrote:
Well actually that error is for all values:
Code:
cmp rax,qword 0
error: not encodable with long immediate.    


Yes, but if you omit the manual type conversion it is just "value out of range" for all values.
I think the "not encodable" message is more clear. Cool
Post 11 Jun 2015, 08:50
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 08:53
shutdownall wrote:
Yes, but if you omit the manual type conversion it is just "value out of range" for all values.
Not quite. It is only "value out of range" for anything outside -2^31 to +2^31-1.
Post 11 Jun 2015, 08:53
View user's profile Send private message Visit poster's website Reply with quote
RIxRIpt



Joined: 18 Apr 2013
Posts: 50
RIxRIpt 11 Jun 2015, 10:24
Thanks for the answers, I think I got it.
That's what I've found:
Code:
;page 622 of Intel's manual
Opcode           Instruction       Op/  64-Bit Compat/   Description
                                   En   Mode   Leg Mode
REX.W + 3D id    CMP RAX, imm32    I    Valid    N.E.    Compare imm32 sign-extended to 64-bits with RAX.
    

and there's no cmp instruction with imm64 operand Confused.
Post 11 Jun 2015, 10:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 11 Jun 2015, 10:42
RIxRIpt wrote:
and there's no cmp instruction with imm64 operand Confused.
The only imm64 available is MOV reg,imm64.
Post 11 Jun 2015, 10:42
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


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

Website powered by rwasa.