flat assembler
Message board for the users of flat assembler.

Index > Main > double precision floating point value

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 13:00
macomics wrote:
Quote:
REX.W + C7 /0 id MOV r/m64, imm32 MI Move imm32 sign extended to 64-bits to r/m64.
That is for 64-bit targets.

For 32-bits target it is zero extended.
Code:
mov rax,imm32 ; sign extended
mov eax,imm32 ; zero extended    
Post 04 Jun 2022, 13:00
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 13:55
So I specified eax to define the single precision format
Otherwise it will turn into a command B8 imm64
Post 04 Jun 2022, 13:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 14:13
macomics wrote:
So I specified eax to define the single precision format
Otherwise it will turn into a command B8 imm64
Yes. So the value written into RAX is zero extended. There is no 0xFF...FF at the beginning. So this below isn't correct:
macomics wrote:
The same thing happens if you write like this
Code:
mov eax, -45.887 ; rax = 0xFFFFFFFFC2378C4A    
It's the same for ADD,/SUB/etc. All 32-bit targets will zero the upper halves.
Post 04 Jun 2022, 14:13
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 14:34
So what about the instruction
Code:
mov rax, sp(-45.887)    
In theory, it should generate a command: 48:С7 С0 С2378C4A
Post 04 Jun 2022, 14:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 14:51
When using a 64-bit target (rax) then there are both imm32 and imm64 forms.

An imm32 form will be sign extended. This is the same for PUSH/ADD/SUB/etc.

An imm64 form, only available for MOV, is the raw value filling the entire register.

If you write mov rax,-3.14 then because it is a 64-bit target fasm uses a DP value.

If you write mov eax,-3.14 then because it is a 32-bit target fasm uses a SP value, and the CPU zero extends.
Post 04 Jun 2022, 14:51
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 14:56
This is great, but how to get exactly such a sequence from fasm1 without crutches.
Code:
mov rax, dword -45.887 ; 48:С7 С0 С2378C4A    
That's why I say that fasm1 loses signs in the bit sequence.
Post 04 Jun 2022, 14:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 15:04
macomics wrote:
This is great, but how to get exactly such a sequence from fasm1 without crutches.
Code:
mov rax, dword -45.887 ; 48:С7 С0 С2378C4A    
That's why I say that fasm1 loses signs in the bit sequence.
Like this.
Code:
mov rax,0x4a8c37c2    
Assuming your hex code is correct.

But if you want the value 0xffffffffca8c37c2 then use this:
Code:
mov rax,0xffffffffca8c37c2    
Do your see the values are different?
Post 04 Jun 2022, 15:04
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 15:11
revolution wrote:
Like this.
Code:
mov rax,0x4a8c37c2    
Then that's it. There the byte order of debugger changed
Code:
mov rax, 0xC2378C4A; B8 00000000C2378C4A    
I need a different sequence with a sign extension.

revolution wrote:
But if you want the value 0xffffffffca8c37c2 then use this:
Code:
mov rax,0xffffffffca8c37c2    
Do your see the values are different?
You're evading the question. The values are different, but then you will have to use the 16th representation to write single-precision real numbers - which is a crutch.

I'm talking about a situation where it's more convenient for me to work so that constants overwrite sign bits when expanding.
That is, once a sign is present in the text representation of a constant, then the bit sequence must also expand by signs.
Post 04 Jun 2022, 15:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 15:26
Okay, I understand your suggestion now.

fasm doesn't tag internal values as float vs int. A float is converted to int and then stored. The sign is used only to format the float value, and no further..

But you can't sign extend a float. They don't have leading bits that work like the ints do. If you pop the value back, with all the extra F's attached, you can't use that as a float, you have to truncate it first.
Post 04 Jun 2022, 15:26
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 15:38
This is clear. Only this breaks the SF flag
Post 04 Jun 2022, 15:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 16:09
A consequence of the storage-as-an-int is that you get a mess if you try to add two values.
Code:
a=3.14
b=2.71
c=a+b ; this value is a complete mess    
Post 04 Jun 2022, 16:09
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 16:17
I'm not going to perform actions with real numbers. Only it would be nice to add fasm1 (real arithmetic).
Code:
value = dword -45.887 ; miss
        push    value or (( -1 * ( value shr 31 )) shl 32 )
        fld dword [rsp] ; st0 = -45.887
        pop rax ; 0xFFFFFFFFC2378C4A
        and rax, 0x7FFFFFFF ; 0x0000000042378C4A
        push rax
        fld dword [rsp] ; 45.887    


Last edited by macomics on 04 Jun 2022, 16:31; edited 1 time in total
Post 04 Jun 2022, 16:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 16:25
Note that the default width for floats is DP.

So using "value = -45.887" gives a full sized DP encoding.

If you want a SP encoding use "value = dword -45.887"

DP -45.887 = 0xc046f189374bc6a8
Post 04 Jun 2022, 16:25
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 18:05
If the sign in the constant was not lost, then comparisons could be made with real numbers at least to find out if it is less than or >= to zero.
As it is, crutches are needed again to work with the format of real numbers.
Post 04 Jun 2022, 18:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 04 Jun 2022, 18:16
macomics wrote:
If the sign in the constant was not lost, then comparisons could be made with real numbers at least to find out if it is less than or >= to zero.
You can do that by examining the top-most bit.
Code:
a=3.14
b=-3.14
if a and 1 shl 63
 display 'a is negative'
end if
if b and 1 shl 63
 display 'b is negative'
end if    
Post 04 Jun 2022, 18:16
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 926
Location: Russia
macomics 04 Jun 2022, 18:24
revolution wrote:
macomics wrote:
If the sign in the constant was not lost, then comparisons could be made with real numbers at least to find out if it is less than or >= to zero.
You can do that by examining the top-most bit.
Code:
a=3.14
b=-3.14
if a and 1 shl 63
 display 'a is negative'
end if
if b and 1 shl 63
 display 'b is negative'
end if    
This was called the crutch.
Post 04 Jun 2022, 18:24
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 712
Ali.Z 08 Jun 2022, 13:42
revolution wrote:
Note that the default width for floats is DP.

So using "value = -45.887" gives a full sized DP encoding.

If you want a SP encoding use "value = dword -45.887"

DP -45.887 = 0xc046f189374bc6a8

only for preprocessor constants?

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


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 08 Jun 2022, 14:34
Variables are defined in the assembler pass.

You can redefine them if you want. They aren't constants. But then you can't forward reference them if you redefine them.
Post 08 Jun 2022, 14:34
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:  
Goto page Previous  1, 2

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

Website powered by rwasa.