H O M E - APOLLO181 INTRODUCTION First Program Example Binary Clock Algorithm Shift-and-Add Multiplication Prime Numbers Benchmark PWM LED Dimmer Step Motor Controller Sound Generator: Part 1 Sound Generator: Part 2 Random Number Generator EPROM Data Storage My Previous Z80 Project

Binary 8-bit multiplication by repeated addition

This is a simple non-optimized program which I used to initially test the capabilities of APOLLO181: this algorithm, that multiplies two integer unsigned 8-bit numbers giving a 16-bit result, uses 14 of the 16 available instructions.

Multiplication here is a repeated addition: the first number is the multiplier and tells how many times to add the second number. The second number is the multiplicand and it is added the number of times stated by the first number, the multiplier.

The main portion of the algorithm (that is the repeated addition of the multiplicand which you can see in the video at slow clock) consists of 28 instructions, from address 19H to address 34H. APOLLO181, if running at 2,5MHz, is able to perform 625000 complete instructions per second, or one instruction every 1,6 microseconds.

In the worst case, that is 255*255 = 65025 (or "1111 1110 0000 0001" in binary), APOLLO181 will perform the calculation in ( 28 * 255 * 1,6 us )= 11,4 ms.

 ADDRESS   INSTRUCTION     DESCRIPTION   00    10   ACC = 0   01    F7   PORT7 = ACC     02    F8   PORT8 = ACC     03    F9   PORT9 = ACC     04    FA   PORTA = ACC     05    24   REG4 = ACC 06    25   REG5 = ACC 07    26   REG6 = ACC 08    27   REG7 = ACC Clear Displays and Registers   09   E7   ACC = PORT7     0A   20   REG0 = ACC 0B   E8   ACC = PORT8     0C   21   REG1 = ACC Input 8-bit Multiplier   0D   1E  0E   00   GOTO 0Eh Wait for Interrupt (infinite cycle)   0F   E7   ACC = PORT7 Resume from Interrupt (Interrupt Vector switches must be set to address "0F")   10   22   REG2 = ACC 11   E8   ACC = PORT8     12   23   REG3 = ACC Input 8-bit Multiplicand   13   4E   SET ALU "A OR B" 14   31   ACC = REG1 15   80   ACC = (ACC OR REG0)  16   A0   COMPARE ACC WITH 0   Check if Multiplier is zero   17   15   IF ZERO GOTO 35h (END) 18   C3        If Multiplier is zero than END   19   90   SET FLAG "NO CARRY" Decrement Multiplier till it is zero   1A   4F   SET ALU "A MINUS 1"  1B   30   ACC = REG0 1C   50   ACC = ACC - 1   1D   20   REG0 = ACC 1E   31   ACC = REG1 1F   50   ACC = ACC - 1 + CARRY     20   21   REG1 = ACC 21   15   IF "CARRY" GOTO 25h If Multiplier is greater than zero then GOTO 25   22   D2        23   15   GOTO 35h (END) else GOTO 35 (END)   24   03        25   90   SET Carry to ZERO Initially SET Carry to Zero   26   49   SET ALU to "1001" ALU 74181 ready to make a Sum   27   32   ACC = REG2 28   64   ACC = ACC + REG4 + CARRY 29   24   REG2 = ACC 2A   33   ACC = REG3 2B   65   ACC = ACC + REG5 + CARRY  2C   25   REG5 = ACC 2D   36   ACC = REG6 2E   50   ACC = ACC + ZERO + CARRY  2F   26   REG6 = ACC 30   37   ACC = REG7 31   50   ACC = ACC + ZERO + CARRY  32   27   REG7 = ACC Execute cascaded 16-bit SUM with CARRY in Arithmetic Mode   33   19        34   01   GOTO 19h  Repeat Addition of Multiplicand   35   34   ACC = REG4 36   F7   PORT7 = ACC     37   35   ACC = REG5 38   F8   PORT8 = ACC     39   36   ACC = REG6 3A   F9   PORT9 = ACC     3B   37   ACC = REG7 3C   FA   PORTA = ACC     3D   1E        3E   03   GOTO 3Eh (STOP) Output 16-bit binary results on four led 4-bit port and STOP