# The Little Man Multiplication Challenge

Document Sample

```					The Little Man Multiplication Challenge

The Little Man Computer may seem a bit odd, but it is a good introduction
to two really important things. The first is the Fetch-Execute cycle, the
underlying process that drives every computer in the same way that the
Four-Stroke cycle drives every car. The second thing you’ll be learning
today, without necessarily realising it, is how to write assembly language.
You will be creating a simple assembly language to instruct the little man
and you will be amazed how much like ‘real’ assembly language it turns

Write a program to multiply the input number by three and output the
result.

Hint: Multiplication is just repeated addition.

We can fairly easily make code that will always multiply one number by
a fixed number – by simply performing ADD as many times as we need.
What is more difficult, but more useful, is to write a program that will
allow us to multiply one input number by another input number. This is
not so easy, since we don’t know how many times we are going to need
to ADD until the program is running.

You’ll probably remember from your BASIC work that you would use a
loop for this, something like:

for i = 1 to input2
result = result+input1
next i

We can do something similar with the Little Man

Skipping and Jumping

Normally the Little Man Computer will execute each instruction in
sequence, because he always looks for instructions where the counter
is pointing and then bumps up the counter by one.

There are two instructions in his code set that allow this to change. I
want you to experiment with them both. The first is the skip instruction

800 – Skip if Negative
801 – Skip if Zero
802 – Skip if Positive

A skip instruction will move the counter past the next instruction in
sequence without executing it. There are three types of skip that
depend on the value of the accumulator – if it is positive, zero or
negative.
The second instruction is a jump instruction. This simply jumps to the
counter value you specify in the operand – for example

The little man will respond to this by entering the operand directly into
the counter.

To multiply one number by another we need to:
Get the first number from the input tray and store it in a location x
Get the second number from the input tray and store it in a location y
Let one further memory location – z be the place for the answer
Create a loop: (say that we start at location 05)

05 – move the answer from z to the accumulator
06 – add the first number from x to the accumulator
07 – put the new answer back into location z
08 – read the counter from location y into the accumulator
09 – subtract one from the accumulator
10 – put the accumulator contents back into y
11 – skip the next instruction if the accumulator is zero
13 – move the answer from z into the accumulator
14 – output the contents of the accumulator
15 – Halt.

Can you make this work?

Give it a try.

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 235 posted: 2/23/2010 language: English pages: 2
Description: The Little Man Multiplication Challenge