Version 6
Version 6 is like version 5 except the expanded ALU is not used. Here are the op codes:
I wrote up an 8 bit multiplication routine, first in C:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
unsigned short mul(unsigned char A,unsigned char B)
{
// Returns:
// A = A * B
unsigned short res=0;
unsigned char i=8; // 8 bit
LOOP:
res=res+res;
if (A>=0x80) {
res=res+B;
}
A=A+A;
i=i-1;
if (i>0) goto LOOP;
return res;
}
int main(void)
{
unsigned char A,B;
unsigned short M;
int i,j;
for (i=0;i<=255;i++) {
for (j=0;j<=255;j++) {
A=(unsigned char)i;
B=(unsigned char)j;
M=mul(A,B);
if (i*j!=M) printf("%6d %6d\n",i*j,M);
}
}
return 0;
}
I tested all cases so I know it works. I then dumbed it down to 4 bits:
unsigned short mult(unsigned char A,unsigned char B)
{
// Returns:
// C = A * B
unsigned short C=0;
unsigned char D=4; // 4 bit
LOOP:
C=(C+C)&0X0F; // 4 bit adjustment
if (A>=8) { // MSB of 4 bit
C=(C+B)&0X0F; // 4 bit adjustment
}
A=(A+A)&0X0F; // 4 bit adjustment
D=(D-1)&0X0F; // 4 bit adjustment
if (D>0) goto LOOP; // 4 bit adjustment
return C;
}
int main(void)
{
unsigned char A,B;
unsigned short C;
A=(unsigned char)5;
B=(unsigned char)3;
C=mult(A,B);
printf("C=5*3 %d\n",C);
return 0;
}
Although the code handles overflow into the high order bit of the result variable (C), in this implementation, I have not considered overflow of C. Therefore 3x5 is big as the algorithm can handle:
Here is the code running:
In the RAM window: A, B, C & D are updated as the program runs. At the end, the output port displays the answer.
The run starts with:
- A=5; Operand
- B=3; Operand
- C=0; Result
- D=4; Bit count
At the end:
- A=0
- B=3
- C=15 ; Correct!
- D=0
- Output=15
Here is a version that handles lager numbers:
If you used A=13 (D) and B=15 (F), then the result would be C=3 and D=12 (C) or 195.
Refer to the Simulation below:
Unfortunately both of these programs are too big for my 32 byte PROM design.
I will check the schematic tomorrow for any missed errors.
Yeah, found two errors, fixed and forwarded for manufacture.
AlanX
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.