flat assembler
Message board for the users of flat assembler.

Index > Main > double precision floating point value

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 535
Ali.Z 01 Jun 2022, 23:40
Code:
dd 1.0e38 ; in-range, single precision
dd 1.0e39 ; value out of range, shouldn't fasm promote it to double precision?    

_________________
Asm For Wise Humans
Post 01 Jun 2022, 23:40
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 535
Ali.Z 01 Jun 2022, 23:47
Ali.Z wrote:
Code:
dd 1.0e39 ; value out of range, shouldn't fasm promote it to double precision?    


nvm, I should have defined it as dq so fasm treats it as a dp-fp value.

_________________
Asm For Wise Humans
Post 01 Jun 2022, 23:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 02 Jun 2022, 01:48
Code:
mov eax,3.1415926 ; always SP for 32-bit destinations
mov rax,3.14159265358979323 ; always DP for 64-bit destinations
dt 3.1415926535897932384626 ; always EP for 80-bit destinations    
Post 02 Jun 2022, 01:48
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 535
Ali.Z 02 Jun 2022, 09:24
thanks, also its good to know that fasm supports ep-fp values.

_________________
Asm For Wise Humans
Post 02 Jun 2022, 09:24
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1498
Location: Toronto, Canada
AsmGuru62 02 Jun 2022, 22:53
push 45.887 -- works in 32-bit code, but fails in 64-bit code.

Anyone knows how to solve it?
Post 02 Jun 2022, 22:53
View user's profile Send private message Send e-mail Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 02 Jun 2022, 23:51
Code:
.value = dword 45.887
        push    .value ; single precision    
or
Code:
macro fpush val { local .value
 .value = dword v
        push    .value }
        fpush   45.887 ; single precision    
or
Code:
        mov     rax, 45.887
        push    rax ; double precision    
Post 02 Jun 2022, 23:51
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1498
Location: Toronto, Canada
AsmGuru62 03 Jun 2022, 20:37
Not bad. Thanks.
Post 03 Jun 2022, 20:37
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: 19098
Location: In your JS exploiting you and your system
revolution 03 Jun 2022, 20:46
Code:
.value = dword -45.887
        push    .value ; single precision    
Code:
        push    .value ; single precision
processed: push .value
error: value out of range.    
You need to use a register if you have negative numbers.
Post 03 Jun 2022, 20:46
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: 19098
Location: In your JS exploiting you and your system
revolution 03 Jun 2022, 20:53
Or an alternative is this:
Code:
use32
push -45.887
push 45.887
use64    
Post 03 Jun 2022, 20:53
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 03 Jun 2022, 23:34
revolution wrote:
Or an alternative is this:
Code:
use32
push -45.887
push 45.887
use64    
Nice
Code:
virtual
  dd -45.887
  load dword .value at $ - 4
end virtual
push .value    
revolution wrote:
Code:
.value = dword -45.887
        push    .value ; single precision    
Code:
        push    .value ; single precision
processed: push .value
error: value out of range.    
You need to use a register if you have negative numbers.
It looks like a bug
Code:
use32
push   45.887 ; 68 4A 8C 37 42
push  -45.887 ; 68 4A 8C 37 C2
use64    
The sign in real numbers is designed just so as to correspond to the additional code of an integer.
Post 03 Jun 2022, 23:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 03:48
You can only push immediate values in the range 0xffffffff80000000 to 0x000000007fffffff.

So 0x00000000c2378c4a is out of range. Just as fasm says.

In 32-bit mode the encoding is exactly the same, and all 32-bit values can be pushed, but it ignores the implicit sign extension. So when you pop it later it gives 0xffffffffc2378c4a which isn't the value pushed, but the lower 32-bits are the same.
Post 04 Jun 2022, 03:48
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 04 Jun 2022, 09:14
So I say it's a bug. A real number (always signed) is converted to an unsigned bit sequence. Intel just didn't give a damn about it and general-purpose registers don't care about it.
Code:
macro fpush value { local .value
    .value = dword value
        push    .value or (( -1 * ( .value shr 31 ) shl 32 ) }    
Post 04 Jun 2022, 09:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 09:50
It would be not good if this were to happen.
Code:
push 0x00000000ffffffff
pop rax ; rax = 0xffffffffffffffff    
Post 04 Jun 2022, 09:50
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 04 Jun 2022, 10:05
revolution wrote:
It would be not good if this were to happen.
Code:
push 0x00000000ffffffff
pop rax ; rax = 0xffffffffffffffff    
That's the whole point. In your example, there is no unary operation "-" and the sequence is unsigned. Real numbers should just give a signed sequence.

Intel has reached the point where even addresses began to be counted in the additional code of integers.
Post 04 Jun 2022, 10:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 11:13
The CPU can't know if your constant is real or int. It is all just bits to the CPU.

So it would be very wrong for the CPU change the data to something else.

If you allow that, you get this also.
Code:
push 0x00000000ffffffff
pop rax ; rax = 0xffffffffffffffff
push 0xffffffffffffffff
pop rax ; rax = 0xffffffffffffffff    
Two different values pushed both giving the same result. Yuck. No thanks. That is awful. The CPU shouldn't change my bits.
Post 04 Jun 2022, 11:13
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 04 Jun 2022, 11:52
I'm not talking about the CPU. This fasm1 loses the sign in their bit sequence when translating real numbers. And controlling the length and the immediate value is already the task of the programmer.

Code:
push 0x00000000ffffffff ; error (unsigned, out of range -0x80000000 .. 0x7FFFFFFF)
push 0xffffffffffffffff ; it is possible to issue a warning about the implicit conversion of a bit into a sign or error (unsigned, out of range -0x80000000 .. 0x7FFFFFFF)
push 0x80000000         ; error (unsigned, out of range -0x80000000 .. 0x7FFFFFFF)
push -0x80000000        ; [rsp] = 0xFFFFFFFF80000000
push -1      ; [rsp] = 0xFFFFFFFFFFFFFFFF
push -45.887 ; [rsp] = 0xFFFFFFFFC2378C4A
push  45.887 ; [rsp] = 0x0000000042378C4A    
Judging by the work of the commands, Intel(AMD) was counting on just this option.
Post 04 Jun 2022, 11:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 12:07
-45.887 is not 0xFFFFFFFFC2378C4A

It also is not 0xFF...FFC2378C4A for any number of leading F's except zero. That is a different value.
Post 04 Jun 2022, 12:07
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 04 Jun 2022, 12:44
revolution wrote:
That is a different value.
Only for unsigned sequences.

The same thing happens if you write like this
Code:
mov eax, -45.887 ; rax = 0xFFFFFFFFC2378C4A    
Post 04 Jun 2022, 12:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19098
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 12:46
macomics wrote:
revolution wrote:
That is a different value.
Only for unsigned sequences.

The same thing happens if you write like this
Code:
mov eax, -45.887 ; rax = 0xFFFFFFFFC2378C4A    
Code:
mov eax, -45.887 ; rax = 0x00000000C2378C4A    
Fixed that for you.

All 32-bit writes are zero extended.
Post 04 Jun 2022, 12:46
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 04 Jun 2022, 12:53
Quote:
REX.W + C7 /0 id MOV r/m64, imm32 MI Move imm32 sign extended to 64-bits to r/m64.
Post 04 Jun 2022, 12:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.