Thread: floating point unit programming problem

  1. #1
    Join Date
    Jan 2003

    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)

    void	Vector3::Normalize()
    #if	1
    	float	basic = x*x + y*y + z*z;
    			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;
    				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;
    	float	magnitude = sqrt( (x * x) + (y * y) + (z * z) );
    		x /= magnitude;
    		y /= magnitude;
    		z /= magnitude;
    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, 07:57 PM
  2. Floating Point Addition
    By ggraz in forum C Programming
    Replies: 10
    Last Post: 10-12-2008, 12: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, 01:30 PM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM