SimCom the Simple Computer 2 Let's try something a bit more useful. How about a program to add two numbers together? First the steps in our language:
Pretty easy huh? Here we go then:
- get a number;
- get another number;
- add the two together;
- output the result.
Does it work?
- "get a number" is easy ... the HELP tells us that it's 1AA where AA is the box that we want the number to go into. It doesn't matter where it goes so let's pick box 20. So the first instruction will be 120.
- The second number can go in box 21 so the instruction will be 121.
- Adding them together is the first tricky part - the HELP tells us that we can only ADD a number to the accumulator so we must copy one number into the accumulator (320) and add the other number to it (521).
- So all we have to do is output the number in the accumulator and we're done. Ahh ... but the only "output" in the HELP is 2AA ie out of a memory box not the accumulator. So we will first have to copy the accumulator to a memory box - let's pick 22 (422) and then output it (222).
- Finally we should stop the computer (0).
Your turn - write a program which inputs one number and outputs it's double. For example, if 7 goes in, 14 comes out. Check.