/*****************************************************************************/
/*									     */
/*  256/32 BIT DIVIDE (UNSIGNED)					     */
/*  01/12/07 (dkc)							     */
/*									     */
/*****************************************************************************/
unsigned int carry(unsigned int a, unsigned int b, unsigned int sum);
unsigned int lmbd(unsigned int mode, unsigned int a);
void div256_32(unsigned int a0, unsigned int a1, unsigned int a2,
	       unsigned int a3, unsigned int a4, unsigned int a5,
	       unsigned int a6, unsigned int a7, unsigned int *quotient,
	       unsigned int d7) {
unsigned int i,d0,d1,d2, d3,d4,d5,d6,dshift,ashift,count,flag;
unsigned int shift,c,c0,c1,c2,c3,c4,c5,c6,temp,temp0,temp1,temp2,temp3;
unsigned int temp4,temp5,temp6,temp7;

if ((a0==0)&&(a1==0)&&(a2==0)&&(a3==0)&&(a4==0)&&(a5==0)&&(a6==0)&&(a7<d7)) {
   *quotient=0;
   *(quotient+1)=0;
   *(quotient+2)=0;
   *(quotient+3)=0;
   *(quotient+4)=0;
   *(quotient+5)=0;
   *(quotient+6)=0;
   *(quotient+7)=0;
   return;
   }
dshift=lmbd(1,d7);
dshift+=224;

ashift=lmbd(1,a0);
if (a0==0)
   ashift+=lmbd(1,a1);
if ((a0|a1)==0)
   ashift+=lmbd(1,a2);
if ((a0|a1|a2)==0)
   ashift+=lmbd(1,a3);
if ((a0|a1|a2|a3)==0)
   ashift+=lmbd(1,a4);
if ((a0|a1|a2|a3|a4)==0)
   ashift+=lmbd(1,a5);
if ((a0|a1|a2|a3|a4|a5)==0)
   ashift+=lmbd(1,a6);
if ((a0|a1|a2|a3|a4|a5|a6)==0)
   ashift+=lmbd(1,a7);

shift=dshift-ashift;
count=shift+1;
d0=0;
d1=0;
d2=0;
d3=0;
d4=0;
d5=0;
d6=0;
if (shift<32) {
   if (shift!=0) {
      d6=d7>>(32-shift);
      d7=d7<<shift;
      }
   flag=7;
   shift=32-shift;
   }
else {
   shift=shift-32;
   d6=d7;
   d7=0;
   if (shift<32) {
      if (shift!=0) {
	 d5=d6>>(32-shift);
	 d6=d6<<shift;
	 }
      flag=6;
      shift=32-shift;
      }
   else {
      shift=shift-32;
      d5=d6;
      d6=0;
      if (shift<32) {
	 if (shift!=0) {
	    d4=d5>>(32-shift);
	    d5=d5<<shift;
	    }
	 flag=5;
	 shift=32-shift;
	 }
      else {
	 shift=shift-32;
	 d4=d5;
	 d5=0;
	 if (shift<32) {
	    if (shift!=0) {
	       d3=d4>>(32-shift);
	       d4=d4<<shift;
	       }
	    flag=4;
	    shift=32-shift;
	    }
	 else {
	    shift=shift-32;
	    d3=d4;
	    d4=0;
	    if (shift<32) {
	       if (shift!=0) {
		  d2=d3>>(32-shift);
		  d3=d3<<shift;
		  }
	       flag=3;
	       shift=32-shift;
	       }
	    else {
	       shift=shift-32;
	       d2=d3;
	       d3=0;
	       if (shift<32) {
		  if (shift!=0) {
		     d1=d2>>(32-shift);
		     d2=d2<<shift;
		     }
		  flag=2;
		  shift=32-shift;
		  }
	       else {
		  shift=shift-32;
		  d1=d2;
		  d2=0;
		  if (shift<32) {
		     if (shift!=0) {
			d0=d1>>(32-shift);
			d1=d1<<shift;
			}
		     flag=1;
		     shift=32-shift;
		     }
		  else {
		     shift=shift-32;
		     d0=d1;
		     d1=0;
		     if (shift!=0)
			d0=d0<<shift;
		     flag=0;
		     shift=32-shift;
		     }
		  }
	       }
	    }
	 }
      }
   }
d0=~d0;
d1=~d1;
d2=~d2;
d3=~d3;
d4=~d4;
d5=~d5;
d6=~d6;
d7=~d7;

temp=d7+1;
c=carry(d7,1,temp);
d7=temp;

temp=d6+c;
c=carry(d6,1,temp);
d6=temp;

temp=d5+c;
c=carry(d5,1,temp);
d5=temp;

temp=d4+c;
c=carry(d4,1,temp);
d4=temp;

temp=d3+c;
c=carry(d3,1,temp);
d3=temp;

temp=d2+c;
c=carry(d2,c,temp);
d2=temp;

temp=d1+c;
c=carry(d1,c,temp);
d1=temp;

d0=d0+c;

for (i=0; i<count; i++) {
   temp7=a7+d7;
   c6=carry(a7,d7,temp7);

   temp=a6+c6;
   c5=carry(a6,c6,temp);


   temp6=temp+d6;
   c5+=carry(temp,d6,temp6);

   temp=a5+c5;
   c4=carry(a5,c5,temp);


   temp5=temp+d5;
   c4+=carry(temp,d5,temp5);

   temp=a4+c4;
   c3=carry(a4,c4,temp);


   temp4=temp+d4;
   c3+=carry(temp,d4,temp4);

   temp=a3+c3;
   c2=carry(a3,c3,temp);


   temp3=temp+d3;
   c2+=carry(temp,d3,temp3);

   temp=a2+c2;
   c1=carry(a2,c2,temp);


   temp2=temp+d2;
   c1+=carry(temp,d2,temp2);

   temp=a1+c1;
   c0=carry(a1,c1,temp);


   temp1=temp+d1;
   c0+=carry(temp,d1,temp1);


   temp0=a0+d0+c0;

   if ((temp0>>31)==0) {
      a0=temp0<<1;
      if ((temp1>>31)!=0)
	 c=1;
      else
	 c=0;
      a0=a0+c;

      a1=temp1<<1;
      if ((temp2>>31)!=0)
	 c=1;
      else
	 c=0;
      a1=a1+c;

      a2=temp2<<1;
      if ((temp3>>31)!=0)
	 c=1;
      else
	 c=0;
      a2=a2+c;

      a3=temp3<<1;
      if ((temp4>>31)!=0)
	 c=1;
      else
	 c=0;
      a3=a3+c;

      a4=temp4<<1;
      if ((temp5>>31)!=0)
	 c=1;
      else
	 c=0;
      a4=a4+c;

      a5=temp5<<1;
      if ((temp6>>31)!=0)
	 c=1;
      else
	 c=0;
      a5=a5+c;

      a6=temp6<<1;
      if ((temp7>>31)!=0)
	 c=1;
      else
	 c=0;
      a6=a6+c;

      a7=temp7<<1;
      a7=a7+1;

      }
   else {
      a0=a0<<1;
      if ((a1>>31)!=0)
	 c=1;
      else
	 c=0;
      a0=a0+c;

      a1=a1<<1;
      if ((a2>>31)!=0)
	 c=1;
      else
	 c=0;
      a1=a1+c;

      a2=a2<<1;
      if ((a3>>31)!=0)
	 c=1;
      else
	 c=0;
      a2=a2+c;

      a3=a3<<1;
      if ((a4>>31)!=0)
	 c=1;
      else
	 c=0;
      a3=a3+c;

      a4=a4<<1;
      if ((a5>>31)!=0)
	 c=1;
      else
	 c=0;
      a4=a4+c;

      a5=a5<<1;
      if ((a6>>31)!=0)
	 c=1;
      else
	 c=0;
      a5=a5+c;

      a6=a6<<1;
      if ((a7>>31)!=0)
	 c=1;
      else
	 c=0;
      a6=a6+c;

      a7=a7<<1;
      }
   }

shift=shift-1;
if (flag==7) {
   a0=0;
   a1=0;
   a2=0;
   a3=0;
   a4=0;
   a5=0;
   a6=0;
   a7=a7<<shift;
   a7=a7>>shift;
   } else
if (flag==6) {
   a0=0;
   a1=0;
   a2=0;
   a3=0;
   a4=0;
   a5=0;
   a6=a6<<shift;
   a6=a6>>shift;
   } else
if (flag==5) {
   a0=0;
   a1=0;
   a2=0;
   a3=0;
   a4=0;
   a5=a5<<shift;
   a5=a5>>shift;
   } else
if (flag==4) {
   a0=0;
   a1=0;
   a2=0;
   a3=0;
   a4=a4<<shift;
   a4=a4>>shift;
   } else
if (flag==3) {
   a0=0;
   a1=0;
   a2=0;
   a3=a3<<shift;
   a3=a3>>shift;
   }
else {
   if (flag==2) {
      a0=0;
      a1=0;
      a2=a2<<shift;
      a2=a2>>shift;
      }
   else {
      if (flag==1) {
	 a0=0;
	 a1=a1<<shift;
	 a1=a1>>shift;
	 }
      else {
	 a0=a0<<shift;
	 a0=a0>>shift;
	 }
      }
   }
*quotient=a0;
*(quotient+1)=a1;
*(quotient+2)=a2;
*(quotient+3)=a3;
*(quotient+4)=a4;
*(quotient+5)=a5;
*(quotient+6)=a6;
*(quotient+7)=a7;
return;
}