Re: Namespaces in assembly language

From: The Wannabee (faq_at_.@.@SZMyggenPV.com)
Date: 08/29/04


Date: Sun, 29 Aug 2004 23:15:19 +0200


> The GCC code is one instruction shorter (the constant 20 is
> stored in floating point format):

Okey. I was just stupid, because I have just to little experience with
this, but the same can be done in RosAsm, of course, I just never used the
R$, F$ before :

[IntegerResult : D$ 0]
[TWenty : R$ 20.0]
Blah:
    fld Q$eax
    fmul R$TWenty
    fistp D$IntegerResult
    mov eax D$IntegerResult
ret

(Now tested, the other code was not, and the FPU stack is also balanced)

However, now I know this, and each day, I add some piece of info to my
memory bank. While using a HLL, you never will know this, as its all taken
care of. But I dont have to set the rounding mode, each time, but only,
when it needs to be changed.

>
> ====================================================
>
> int blah(double x){return (int)(20 * x);}
>
> ====================================================
>
> .section .text
> .p2align 2
> LC0:
> .long 1101004800
> .p2align 4,,15
> .globl _blah
> _blah:
> pushl %ebp
> movl %esp, %ebp
> pushl %eax ; local variable
> pushl %eax ; local variable
> flds LC0
> fmull 8(%ebp)
> fnstcw -2(%ebp) ; save FPU conrol
> movw -2(%ebp), %dx
> movb $12, %dh
> movw %dx, -4(%ebp)
> fldcw -4(%ebp) ; set rounding mode
> fistpl -8(%ebp)
> fldcw -2(%ebp) ; restore FPU control
> movl -8(%ebp), %eax ; return value -> eax
> movl %ebp, %esp
> popl %ebp
> ret



Relevant Pages

  • Re: converting float to ascii w/o printf
    ... Currently I am using sprintfto format this output into ... the rule here is never use floating point at all if it can be avoided. ... If you know what the range of values and required accuracy is, scaled integer arithmetic will be faster and more efficient, especially if you can arrange the data to allow shifts, rather than multiply and divide. ... Floating point on small machines is slow, inefficient, adds complexity and rounding errors everywhere it's used and you can usually get better control and predictable accuracy using other methods. ...
    (comp.arch.embedded)
  • Re: converting float to ascii w/o printf
    ... Currently I am using sprintfto format this output into ... this is using simple multiplies and ... check if you have the ftoa function available. ... Do you really need to store the information in floating point format? ...
    (comp.arch.embedded)
  • Re: format
    ... Do your thing with format and edit vfstab again. ... be people with root access who don't see any consequences for being stupid. ...
    (comp.unix.solaris)
  • Re: [Q] Text vs Binary Files
    ... floating point and other more exotic formats). ... format in which a binary file is stored. ... have no text editor but do have a hex editor, ... you have a copy of the relevant file format standard, ...
    (comp.programming)
  • Re: converting float to ascii w/o printf
    ... Currently I am using sprintfto format this output into ... this is using simple multiplies and ... check if you have the ftoa function available. ... Do you really need to store the information in floating point format? ...
    (comp.arch.embedded)