SimCom the Simple Computer SimCom has
So what can go in the memory boxes? There is room for 4 digits in a memory box. The four digits are sometimes broken into TWO parts by SimCom
- 100 memory boxes labelled 00,01,02,...,98,99 - this number is called the address;
- a Program Counter (the yellow rectangle) which tells us which memory box the computer is currently looking at;
- an Accumulator which is a special memory box - its importance will become apparent later;
- a keypad for entering numbers;
- a Printer - this is where SimCom can display a result for the outside world;
- a GREEN button which starts and stops SimCom;
- a YELLOW button which allows us to run a program one step at a time;
- a ZERO button which empties all the memory boxes and sets the Program Counter to 00.
Here's a simple example: 785. "7" means "jump to" so 785 means "jump to box 85". Why not try it?
- the last two digits - this is the address of a memory box;
- the other digits (one or two) - these tell SimCom what to do with the address.
Type 785, press enter, click box 00 and click the GREEN button.
SimCom has 18 instructions (Assembler equivalents in brackets): 0 halt (HLT). 2 return from subroutine (RTS). 3 load the accumulator with the number in the next box (LDA #). 5 add the number in the next box to the accumulator (ADD #). 6 subtract the number in the next box from the accumulator (SUB #) 1AA input a number from the keyboard into box AA (INP). 2AA output the number in box AA to the printer (OUT). 3AA copy the number in box AA into the accumulator (LDA). 4AA copy the number in the accumulator into box AA (STA). 5AA add the number in box AA to the accumulator (ADD). 6AA subtract the number in box AA from the accumulator (SUB). 7AA jump to box AA (JMP). 8AA jump to the subroutine starting at box AA (JSR). 9AA branch to box AA if the accumulator is negative (BMI). 10AA branch to box AA if the accumulator is equal to zero (BEQ). 11AA branch to box AA if the accumulator is positive (BPL). 12AA add one to box AA (INC). 13AA subtract one from box AA (DEC).So let's try something a bit more useful than jumping to box 85. 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.
- "get a number" is easy ... the table shows 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 table shows 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" listed 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).
- Jump back to the start for another sum (700).
Here's the final program:
00 120 01 121 02 320 03 521 04 422 05 222 06 700You can now save this program by pressing the ORANGE button - it will be saved as Number 1. It may be recalled at any time with the BLUE button.
Your turn! Write a program to input one number and print its double. Drag your mouse across the space below to see my answer.
00 120 01 320 02 520 03 421 04 221 05 700My most complex program to date is one to generate the prime numbers. Press the P key to check it out. Best to run it at full speed!
And here's some little challenges for you ...
- add two numbers (my example above)
- double a number (already done)
- teach SimCom to count ... i.e. print 1,2,3,4...
- how about a countdown from 10 to 0?
- print out the even numbers ... i.e. 2,4,6,8,...
- print out the odd numbers ... i.e. 1,3,5,7,...
- multiply two numbers;
- square a number;
- print out the square numbers ... i.e. 1,4,9,16,...
- print out the Fibonacci numbers ... 1,1,2,3,5,8,13,...
- divide one number by another and print the quotient and the remainder.
My answers Finally, here's a neat demonstration of how a tiny program can wipe out an entire computer. Enter this program and press the green button:
97 200 98 1297 99 797Some Extension Ideas:
- What is the largest number SimCom can store?
- Try to discover or work out the largest:
that SimCom can produce.
- even number
- odd number
- square number
- Fibonacci number
- What is the result of 9999+1 on SimCom?
The last question opens up a whole new world of investigation if you're into negative numbers. The answer means that 9999 is the same as -1 on SimCom.
So -2 would be 9998 and -3 would be 9997.
If you're prepared to leave your SimCom running overnight, try 9998 x 9997. Another approach is to use a calculator.
What about 9998 + 9997 ?
And ... 9997 x 2?
Computer afficiandos will recognise that this is how real computers deal with negative numbers.