# Homework Help: Stuck on little man computer language don't get help please!

1. Feb 21, 2013

### cduval04

1. The problem statement, all variables and given/known data
trying to write a program for school. the program is supposed to do the following:

Write a program that takes an input value (for example, a number 5). The output should be sum of all numbers from 1 to the value input by the user (in this example, the output would be 1+2+3+4+5 i.e. 15)

what I dont get is how if say I enter 20 how to get it to know that I entered 20 and just add all the numbers from 1 to 20 like count. would I use the SUB (subtract) command to aid in this? help-I'm stuck!!

2. Relevant equations

3. The attempt at a solution
INP
STA NUM1
LDA NUM1
INP
STA NUM2
LDA NUM2
OUT
HLT

2. Feb 22, 2013

### Staff: Mentor

Hi cduval04! http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif [Broken]

I'm not au fait with your language, but they are all much the same.

Usually you'd do something like loop though a set of instructions repeatedly subtracting 1 each time until the result tests as being equal to 0, at which time you would exit the loop and know that you had executed it N times, where N is the number that was originally input.

So you need to look over your instruction set, and find an instruction that allows you to JUMP or GOTO some line in the code if the accumulator is zero (or maybe non-zero), or something like that.

All clear now?

Last edited by a moderator: May 6, 2017
3. Feb 22, 2013

### NemoReally

It knows you've entered a value after executing the INP command - the value is then in the accumulator. The STA command stores the accumulator value in the stated location (eg, NUM1 and NUM2 in your example).

You need to lookup the use of labels and the branch commands to make loop decisions. Yes, you could use the SUB command, probably the best way as it makes using the BRZ command easier.

Not that I know anything about the LMC, but I just looked it up on Google ... http://en.wikipedia.org/wiki/Little_man_computer - in fact, look at the "count down to zero" example on this page for a starting point for your problem.