
#include "asm_math.h"


// musi byt globalni kvuli ASM
unsigned int multipd_l;
unsigned int multipd_h;
unsigned int multipr_l;
unsigned int multipr_h;
unsigned int qotient_l;
unsigned int qotient_h;

unsigned int divid_l;
unsigned int divid_h;
unsigned int divis_l;
unsigned int divis_h;


/************************************************************************************
Name:			my_mul32
Description:	nasobeni 32-bitovych cisel, vola asm fci SUM32() 
************************************************************************************/
__attribute__ ((section (".page0f11")))
tULong mul32(tULong multiplicand, tULong multiplier)  // multiplier je to cim se nasobi
{
	tULong retvalue;
	

	multipd_l = multiplicand;
	multipd_h = (multiplicand>>16);

	multipr_l = multiplier;
	multipr_h = (multiplier>>16);

// vstupni data
	asm ("mov.w _multipd_l, r0");		// dividend low int
	asm ("mov.w _multipd_h, r2");

	asm ("mov.w _multipr_l, r1");		// dividend high int
	asm ("mov.w _multipr_h, r3");

	MULTIPLE32();

// vysledek	
	asm ("mov.w r0, _qotient_l");		// vysledek low int
	asm ("mov.w r2, _qotient_h");		// vysledek high int

	retvalue  = qotient_h;				// ziskani vysledku
	retvalue = retvalue << 16;
	retvalue |= qotient_l;

   return (retvalue);					// vysledek

}



/************************************************************************************
Name:			my_div32
Description:	deleni 32-bitovych cisel, vola asm fci DIVIDE32() 
************************************************************************************/
__attribute__ ((section (".page0f12")))
tULong div32(tULong dividend, tULong divisor)  // divisor je to cim se deli
{
	tULong retvalue;
	
	divid_l = dividend;
	divid_h = (dividend>>16);

	divis_l = divisor;
	divis_h = (divisor>>16);

// vstupni data
	asm ("mov.w _divid_l, r0");		// dividend low int
	asm ("mov.w _divid_h, r2");

	asm ("mov.w _divis_l, r1");		// dividend high int
	asm ("mov.w _divis_h, r3");

	DIVIDE32();

// vysledek	
	asm ("mov.w r0, _qotient_l");		// vysledek low int
	asm ("mov.w r2, _qotient_h");		// vysledek high int

	retvalue  = qotient_h;				// ziskani vysledku
	retvalue = retvalue << 16;
	retvalue |= qotient_l;

   return (retvalue);					// vysledek

}




