flat assembler
Message board for the users of flat assembler.
Index
> Main > double precision floating point value Goto page Previous 1, 2 |
Author |
|
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 |
|||
04 Jun 2022, 13:55 |
|
revolution 04 Jun 2022, 14:13
macomics wrote: So I specified eax to define the single precision format macomics wrote: The same thing happens if you write like this |
|||
04 Jun 2022, 14:13 |
|
macomics 04 Jun 2022, 14:34
So what about the instruction
Code: mov rax, sp(-45.887) |
|||
04 Jun 2022, 14:34 |
|
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. |
|||
04 Jun 2022, 14:51 |
|
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 |
|||
04 Jun 2022, 14:56 |
|
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,0x4a8c37c2 But if you want the value 0xffffffffca8c37c2 then use this: Code: mov rax,0xffffffffca8c37c2 |
|||
04 Jun 2022, 15:04 |
|
macomics 04 Jun 2022, 15:11
revolution wrote: Like this. Code: mov rax, 0xC2378C4A; B8 00000000C2378C4A revolution wrote: But if you want the value 0xffffffffca8c37c2 then use this: 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. |
|||
04 Jun 2022, 15:11 |
|
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. |
|||
04 Jun 2022, 15:26 |
|
macomics 04 Jun 2022, 15:38
This is clear. Only this breaks the SF flag
|
|||
04 Jun 2022, 15:38 |
|
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 |
|||
04 Jun 2022, 16:09 |
|
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 |
|||
04 Jun 2022, 16:17 |
|
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 |
|||
04 Jun 2022, 16:25 |
|
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. |
|||
04 Jun 2022, 18:05 |
|
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. 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 |
|||
04 Jun 2022, 18:16 |
|
macomics 04 Jun 2022, 18:24
revolution wrote:
|
|||
04 Jun 2022, 18:24 |
|
Ali.Z 08 Jun 2022, 13:42
revolution wrote: Note that the default width for floats is DP. only for preprocessor constants? _________________ Asm For Wise Humans |
|||
08 Jun 2022, 13:42 |
|
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. |
|||
08 Jun 2022, 14:34 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.