Stuck on little man computer language don't get help please

In summary, the LMC is a computer built in the early 1960s that consisted of a single-board computer with a simple instruction set and was used for research in control and signal processing.
  • #1
cduval04
1
0

Homework Statement


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 don't 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!


Homework Equations





The Attempt at a Solution


INP
STA NUM1
LDA NUM1
INP
STA NUM2
LDA NUM2
ADD NUM2
OUT
HLT
 
Physics news on Phys.org
  • #2
cduval04 said:
what I don't 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!
Hi cduval04! http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif

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

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? :wink:
 
Last edited by a moderator:
  • #3
cduval04 said:

Homework Statement


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 don't 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!


Homework Equations



The Attempt at a Solution


INP
STA NUM1
LDA NUM1
INP
STA NUM2
LDA NUM2
ADD NUM2
OUT
HLT
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.
 

FAQ: Stuck on little man computer language don't get help please

1. What is the Little Man Computer (LMC) language?

The Little Man Computer (LMC) language is a simplified machine language used for teaching basic programming concepts. It is based on the von Neumann architecture and consists of basic instructions such as load, store, add, subtract, input, and output.

2. How does the LMC language work?

The LMC language works by using a set of basic instructions that are stored in the computer's memory. These instructions are then executed by the "little man" or simulated processor, which moves through the memory and performs the specified operations.

3. What are the main features of the LMC language?

The main features of the LMC language include its simplicity, as it only has a limited set of basic instructions, and its ability to simulate a real computer's architecture, making it a useful tool for teaching basic programming concepts.

4. Can I write complex programs in the LMC language?

While the LMC language is not designed for writing complex programs, it is possible to write more advanced programs by combining multiple instructions and using loops and conditional statements. However, it is best suited for teaching basic programming concepts.

5. Where can I find help with the LMC language?

There are many online resources available for learning and getting help with the LMC language, such as tutorials, forums, and communities of LMC enthusiasts. Additionally, most programming textbooks or courses that cover the LMC language also provide support and resources for learners.

Similar threads

Replies
18
Views
6K
Replies
7
Views
2K
Replies
8
Views
10K
Replies
7
Views
8K
Replies
4
Views
4K
Replies
2
Views
2K
Replies
7
Views
6K
Back
Top