MULD M instruction implemented
in MIC-1:
sum = 0;
for (i = 0; i < 15; i++) {
if (high bit of a is 1)
sum += b;
sum += sum;
a += a;
}
if (high bit of a is 1)
sum += b;
MULD implementation:
The operands are popped from the top of the stack and the accumulator holds the final result. It is assumed that the result fits into 16 bits.
pop multiplicand from stack and put in register A
pop multiplier from stack and put in register B
I = -1 (Keep I in register C)
sum = 0 (Keep sum in the accumulator)
top_loop:
shift sum left
if (b is Negative) go to add_in:
go to shift_B
add_in:
sum = sum + a
shift_B:
left shift B
left shift I
if (I is ZERO) go to 0
go to top_loop
NOTE: The ac has no special role at the MIC-1 level so we don't need to reserve
it for performing operations. (This is a point that often confuses people.)
11111110yyyyyyyy DESP y
11111111-------- MULD x
0000xxxxxxxxxxxx