flat assembler
Message board for the users of flat assembler.

Index > Main > Arithmetic Operators

Author
Thread Post new topic Reply to topic
LeftyG



Joined: 12 Sep 2023
Posts: 4
LeftyG 12 Sep 2023, 01:52
Hi all,

I'm a bit new to x86 assembly programming. I was wondering what are the arthmetic operators for fasm? Like +, -, etc. I did a quick look through the documentation, but using / for division comes up with reserved word error when I try to compile.
Post 12 Sep 2023, 01:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20453
Location: In your JS exploiting you and your system
revolution 12 Sep 2023, 02:56
fasm uses the standard +, -, *, / for basic arithmetic.

Show the code that gave an error. Division definitely uses /
Code:
mov eax, 10 / 3    
Post 12 Sep 2023, 02:56
View user's profile Send private message Visit poster's website Reply with quote
LeftyG



Joined: 12 Sep 2023
Posts: 4
LeftyG 12 Sep 2023, 03:22
I'm trying to make a wrapper for Raylib, its a WIP.

https://github.com/raysan5/raylib/blob/master/src/raylib.h

Code:
;this works as well
format PE GUI 4.0

include 'macro/struct.inc'
include 'macro/import32.inc'
include 'macro/export.inc'

;this works
RAYLIB_VERSION_MAJOR = 4
RAYLIB_VERSION_MINOR = 5
RAYLIB_VERSION_PATCH = 0
RAYLIB_VERSION = "4.5"  

PI = 3.14159265358979323846f
DEG2RAD = PI / 180.0f ;this produces a error
RAD2DEG = 180.0f / PI ;same error

;this works too
section '.idata' import data readable writeable
        library raylib, 'RAYLIB.DLL'

        import raylib,\
        InitWindow,'InitWindow'
    
Post 12 Sep 2023, 03:22
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 805
Location: Russian Federation, Sochi
ProMiNick 12 Sep 2023, 03:55
fasm able only to define floating point constants, not produce operations over them.
All arithmetic operations operate only integers and they are only integer operations.
so, applying integer operation over floating point constant cause error.

That not mean thou have no ability to produce fp operations at all.
Thou could define fp constant in virtual memory and emulate producing of such operations (split producing of mantissa and so on...).
With much of time thour and preprocessor you both could do so. But more productable to calculate fp outside of fasm and define only fp results of such calculations.
Post 12 Sep 2023, 03:55
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: 20453
Location: In your JS exploiting you and your system
revolution 12 Sep 2023, 04:10
For floats you need to precalculate.
Code:
PI = 3.14159265358979323846264338327950288
DEG2RAD = 0.0174532925199432957692369076848861271 ; pi /180
RAD2DEG = 57.2957795130823208767981548141051703 ; 180 / pi    
Note: Those have far too much extra precision for the standard 64-bit IEEE, but fasm will round it to fit.
Post 12 Sep 2023, 04:10
View user's profile Send private message Visit poster's website Reply with quote
LeftyG



Joined: 12 Sep 2023
Posts: 4
LeftyG 12 Sep 2023, 07:03
Thanks for the tips. This has come in handy.
Post 12 Sep 2023, 07:03
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.