flat assembler
Message board for the users of flat assembler.

Index > Main > "Number comma"

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 06 Mar 2018, 18:07
(sorry for the title, but I don't know how to say "nombre à virgule" in English, and Google Translation didn't give me any better ^^).

So, for starters, hello!
How do I write comma numbers in FASM?
I've been trying that:
Code:
nbr dd 0.97    

But, no surprises, it didn't work. Do you have any idea?

_________________
The best way to predict the future is to invent it.
Post 06 Mar 2018, 18:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20409
Location: In your JS exploiting you and your system
revolution 06 Mar 2018, 22:21
What do you mean by "didn't work".

The line of code above assembles fine. It produces the closest possible approximation of 97/100 in the single precision floating point format.


Last edited by revolution on 08 Mar 2018, 03:29; edited 1 time in total
Post 06 Mar 2018, 22:21
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 07 Mar 2018, 01:34
Code:
org 100h

num dd 1'234'567'890
rd 1
num2 dd 1_234_567_890
    


Quote:

#echo say d2x(1234567890) | rexx
499602D2

#fasm comma.asm
flat assembler version 1.72 (1048576 kilobytes memory)
1 passes, 12 bytes.

#db -q comma.com
D2 02 96 49 00 00 00 00 D2 02 96 49
Post 07 Mar 2018, 01:34
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 07 Mar 2018, 19:05
Well, when I try to perform a mathematical operation (in this case imul), it refers to value that I don't expect. Like, for example:

Code:
mov eax, 0.97
imul eax, 10
...
; printf("%f", eax);
    


Well, that's basically it. (because my code is longer).

@rugxulo: I didn't quite understand your answer Confused

_________________
The best way to predict the future is to invent it.
Post 07 Mar 2018, 19:05
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 414
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 07 Mar 2018, 20:50
Float multiply by constant:
Code:
Number dd 0.97
Const dd 10
Result dq ?
...
fld [Number]
fimul [Const]
fistp [Result]    

_________________
smaller is better
Post 07 Mar 2018, 20:50
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 07 Mar 2018, 21:16
Good joke, Mino.
Integer & float datas coded differently.
So, for correct interpretation of thour data thou shold use integer instructions for extracting integer operands, or use float instructions for extract float operands.
Post 07 Mar 2018, 21:16
View user's profile Send private message Send e-mail Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 08 Mar 2018, 00:43
There are a few ways to represent numbers with fractional parts, the one you were using was single precision.

So, at the 'nmbr' label, or in eax, the bits are stored as binary scientific notation, more or less. The encoding is pretty standard (I think there can be some variations though), but the IEEE standard for single precision looks like this:

https://en.wikipedia.org/wiki/Single-precision_floating-point_format

which processors can handle pretty efficiently. I think one of the earlier single precision formats was used or invented by Konrad Zuse.

Other "nombre à virgule" formats include binary coded decimal, which can be useful when exact numbers are needed (relational databases have the same type of format).

So, when you are working with integers only, the register will not need the binary exponential format, but probably work on a two's-complement format:

https://en.wikipedia.org/wiki/Two%27s_complement

depending on what you are using the register for. I think add, imul, etc use two's complement. The AMD/intel instruction manuals should be able to confirm.

Also, I think it is more recommended to use non-FPU registers when available, so performanig math operations on floating point numbers can be achieved with SSE/avx/etc instructions on the xmm/ymm/zmm registers (depending on what you have). I saw you were using eax and dd, so not sure if you have an older 32-bit architecture that only supports mmx.

I think fasm will define single precision or double precision for you, when you supply immediates as you have. Since single precision is a 32-bit format, dd should encode that, dq should encode 64-bit (double precision).

A useful SSE instruction is cvtsi2ss and its variants. These are listed in the AMD docs and lets the processor convert between integers and floating point formats.

Sorry for the lengthy response, but think I convered some of the topics you brought up. I can provide some small usage examples if needed.
Post 08 Mar 2018, 00:43
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 08 Mar 2018, 01:00
Mino wrote:
@rugxulo: I didn't quite understand your answer Confused


Well, I don't understand what "nombre à virgule" means. You also said "comma numbers" and used "0.97" (which is not a comma, at least in U.S.).

Quote:

https://en.wikipedia.org/wiki/Virgule

"twig", either '/' (slash) or '|' (pipe) or ',' (comma).


I thought you just meant separating numeric literals for better readability, but apparently you want floating point stuff. Fun! Shocked
Post 08 Mar 2018, 01:00
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 163
Mino 08 Mar 2018, 16:49
@rugxulo: Sorry, in French, we have another name for floats. And translated "literally", that gives a "comma number" (because FR use ',' as comma in float → 0,97 = 0.97).
@donn: Thank's for informations Smile
@ProMiNick: I don't understand very well "my" joke, but thanks also for informations Smile
@CandyMan: It's clearer now, thank you Smile
Post 08 Mar 2018, 16:49
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.