I realise this is prolly the hardest kind of code to understand, but I wrote up a C program that kinda mimics how an ALU could divide...
Code:
#include <stdio.h>
typedef unsigned short reg;
void divide (reg dividend, reg divisor, reg * quotient, reg * remainder);
int main ()
{
reg d1, d2, d3, d4;
d1 = 1;
for (;d1 != 0;)
{
scanf ("%hl", &d1);
scanf ("%hl", &d2);
divide (d1, d2, &d3, &d4);
printf ("%d r %d\n", (int) d3, (int) d4);
}
return 0;
}
void divide (reg dividend, reg divisor, reg * quotient, reg * remainder)
{
unsigned long divisor2;
int i;
divisor2 = divisor << 16;
*quotient = 0x00;
for (i = 0; i <= 16; i++)
{
if (dividend >= divisor2)
{
dividend -= divisor2;
*quotient |= 0x01;
}
*quotient <<= 1;
divisor2 >>= 1;
}
*quotient >>= 1;
*remainder = dividend;
return;
}
Don't have time to explain it much more. Just need to point out that the divide function obviously has all the logic, I'm not too sure how they'd set up the count i in the ALU, but I don't doubt that it's possible.