The edit before the publish: So I kinda pretty much figured it all out on my own only AFTER I had the whole freakin' question typed out and neatly arranged. So as not to work for nothing, I'm posting this anyways, asking if this is actually right, and asking for any suggestions/comments. I'm still not sure about one thing.
Alright, so I am a complete noob to computer science. Right now I am learning about assembly-language and machine language programming. This is a homework question so please help me understand, don't throw answers in my face. I am trying to write a program that gets the sum of the numbers from 1 to 20 (the answer is 210) using branch on condition (a loop).
The Mnemonics used are:
L for load A for Add St for store BC for branch on condition C for compare CH for channel
There are 10 registers to put stuff into.
So basically I have to do 2 things: 1) Figure out a way to add up all numbers from 1 to 20 (1+2+3+4+5+6+7+8+9+...+20) which includes making a loop, AND 2) create a counter so it knows to stop when it gets to twenty. Is this right??
START L R1,COUNT A R1,ONE ST R1,COUNT A R2,COUNT C R1,TWENTY BC 3,??? ST R2,SUM CH SUM STOP COUNT DC F'0' ONE DC F'1' TWENTY DC F'20' END START
All this is saying: Load Register1 with contents of COUNT (which to begin with is 0). Add to Register1 contents of ONE (which is 1). Store this new number that's in Register1 into COUNT. Add this new number to Register2. Compare contents of COUNT with contents of TWENTY (which is 20). Branch (/repeat) if the number inside COUNT is less than or equal to 20 (3 is the condition code). Once the counter reaches 20, the condition will be broken and the instruction will go to the next line which is: Store the number which is in Register2 (which should now be 210) into variable SUM. Then call CHannel to display contents of SUM on I/O device. Then STOP.
Now... I don't know how to specify to branch/return back up to the beginning, so it repeats the process until the counter reaches 20. I'm also not sure if I should specify COUNT as 0 or not.
Thanks for any/all help.