Doing multiplication using the Little Man Computer instructions can be quite a challenge for newcomers. Once you can do it, you will be well on your way to the level of mastery required for exams such as Computer Science GCSE and A Level.
One big area of difficulty in writing the instructions is understanding exactly how the process of multiplication works. Many people get as far as understanding that we need to use repeated addition, but are still confused by the details.
The key here is to understand or remember that in multiplication, each operand has a different role. So even though 5 * 4 = 4 * 5 for example, the roles of the 4 and 5 are different in each case.
Let’s look at the second version: 4 * 5. By convention, the 4 here is called the multiplier, and the 5 is called the multiplicand. The multiplicand is “the thing to be multiplied”, so 4 * 5 now unambiguously represents 5 + 5 + 5 + 5 + 5.
With that clarity, writing the instructions becomes much easier.
In pseudocode, we have:
Read input into R0 and R1
Set RESULT to 0
While R1 > 0
Subtract 1 from R1
Add R0 to RESULT
Here, R0 and R1 play completely different roles. R0 is the multiplicand and R1 is the multiplier. With this clarity, the implementation becomes much easier to understand. You should try to do it yourself before looking at the solution below. Good luck!
LOOP LDA R1
END LDA RES
// Temporary storage
// R1 is multiplier
// R0 is multiplicand
ONE DAT 1
Little Man Computer Programming Teaching Pack for Computer Science GCSE and A Level
You can check out a great resource for teaching or learning about Little Man Computer Programming by clicking here or on the image below.