flat assembler
Message board for the users of flat assembler.

Index > Main > its time to float numbers

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2011, 14:21
Hi.

I never worked with float numbers in assembly. I dunno where or how to start. Any link to article/tutorial is apreciated. Any quicky introduction here are welcome too.

Thanks in adv.

_________________
Sorry if bad english.
Post 30 May 2011, 14:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4332
Location: Now
edfed 30 May 2011, 14:51
start with some methodology, with FP, it is better to always comment the code.

like this:
Code:
        finit                   ; EMPTY
        fld1
        fimul dword[ss:esp+4]
;        fidiv dword[ss:esp]
        fadd [.angle]
        fstp [.angle]
        fldpi                   ; pi        ;
        fmul [.angle]           ; pi*angle  ;
        fdiv dword[ss:esp+8]    ; rad       ;
        fsincos                 ; cos       ; sin
        fld [.module]           ; module    ; cos       ; sin
        fimul dword[ss:esp+4]   ; ticks*mod ; cos       ; sin
        fidiv dword[ss:esp]     ; pixels    ; cos       ; sin
        fxch                    ; cos       ; pixels    ; sin
        fmul st0,st1            ; cos*pix   ; pixels    ; sin
        fadd [.x]               ; x         ; pixels    ; sin
        fst [.x]                ;
        fsub [.rayon]           ;
        fistp dword[eax+item.x] ; pixels    ; sin
        fmul st0,st1            ; pix*sin   ;
        fsubr [.y]              ; y
        fst [.y]                ;
        fsub [.rayon]           ;
        fistp dword[eax+item.y] ; EMPTY
    


look at some codes from djmauretto, he submitted a lot of good code with fpu.

and forget everything you know about general purpose assembly, fpu is a lot different, on many points.

there are effectivelly 8 registers, but they are 80 bits wide.
they are effectivelly 8, but are disposed as a stack.
st0 is the top of stack register.

the stack can be empty, full, trashed, etc...
don't mix MMX code and FPU code.
etc, etc...
a good tutorial is linked somewhere in the faq, i think it redirects to x86asm.net site.
Post 30 May 2011, 14:51
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 May 2011, 18:03
Then registers st0 to st7...

1. disposed as a stack? these registers live in CPU or memory? whats exactly "disposed as a stack" means: do i have an order to follow in order to access them? (i'm thinking on push/pop)
2. whats the difference among MMX & FPU?
3. what do you mean by empty, full, trashed..
4. why they're 80bits wide?

sorry Embarassed

_________________
Sorry if bad english.
Post 31 May 2011, 18:03
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 31 May 2011, 21:38
Post 31 May 2011, 21:38
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 31 May 2011, 21:53
Post 31 May 2011, 21:53
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 01 Jun 2011, 00:01
Teehee wrote:
Then registers st0 to st7...

1. disposed as a stack? these registers live in CPU or memory? whats exactly "disposed as a stack" means: do i have an order to follow in order to access them? (i'm thinking on push/pop)
2. whats the difference among MMX & FPU?
3. what do you mean by empty, full, trashed..
4. why they're 80bits wide?

sorry Embarassed


It works like that:
Code:
fld dword[variable] ;loads variable to st0
fld dword[constant];loads constant to st0, and what was is st0 goes to st1
fmul st0,st1;multiplies st0 by st1 - st0 holds the result and st1 holds variable
fstp dword[value];store what's in st0 to value, pop(delete) what's in st0, and what's in st1 goes to st0
    


So, for example:
Code:
fld [a]
fld [b]
fld [c]
;gives st0 = c, st1 = b, st2 = a
fstp[d]
;gives st0 = b, st1 = a, st2 = empty
    


Like an HP calculator in RPN mode.
Post 01 Jun 2011, 00:01
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.