floating point unit programming problem

This is a discussion on floating point unit programming problem within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I'm bored, no school today, so I'm learning how to do assembly with the floating point unit instruction set. I'm ...

  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    floating point unit programming problem

    I'm bored, no school today, so I'm learning how to do assembly with the floating point unit instruction set. I'm trying to normalize a vector, but I cannot access the vector's x,y,or z components, instead i've got to copy to a local variable. Any way around doing that? Here's the code (with comments)

    Code:
    void	Vector3::Normalize()
    {
    #if	1
    
    	float	basic = x*x + y*y + z*z;
    		_asm
    		{
    			FLD	basic; //Put basic length into st(0)
    			FSQRT;		//Put SQUARE ROOT of basic into st(0)
    			FSTP basic; //Store square root of basic into memory address of basic, pop stack
    		}
    		if(basic>.0001) //won't ever be exactly zero
    		{
    			//Can't seem to access this->x,y,or z
    			float	x1 = x;
    			float	y1 = y;
    			float	z1 = z;
    			_asm
    			{
    				FLD	x1;			//Load into FPU stack element zero
    				FDIV	basic;	//divide by length
    				FSTP	x1;		//store in x1 and pop stack 
    
    				FLD	y1;
    				FDIV	basic;
    				FSTP	y1;
    
    				FLD z1;
    				FDIV	basic;
    				FSTP	z1;
    			}
    			x =	x1;
    			y = y1;
    			z = z1;
    		}
    #else
    	float	magnitude = sqrt( (x * x) + (y * y) + (z * z) );
    	if(magnitude)
    	{
    		x /= magnitude;
    		y /= magnitude;
    		z /= magnitude;
    	}
    #endif
    }
    Last edited by Silvercord; 12-15-2003 at 02:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 08:57 PM
  2. Floating Point Addition
    By ggraz in forum C Programming
    Replies: 10
    Last Post: 10-12-2008, 01:29 PM
  3. Floating point checking problem
    By ikkiutsu in forum C Programming
    Replies: 8
    Last Post: 12-03-2003, 06:35 AM
  4. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21