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

Click For Summary
SUMMARY

The discussion centers on programming a solution using the Little Man Computer (LMC) language to calculate the sum of all numbers from 1 to a user-input value. The user seeks clarification on how to implement a loop that continues until the accumulator reaches zero, using commands like INP, STA, LDA, ADD, and SUB. The solution involves storing the input value and iteratively subtracting until reaching zero, utilizing branch commands for loop control. The recommended approach includes referencing the "count down to zero" example from the LMC documentation for further guidance.

PREREQUISITES
  • Understanding of Little Man Computer (LMC) architecture and instruction set
  • Familiarity with basic programming concepts such as loops and conditionals
  • Knowledge of accumulator-based computation
  • Ability to read and interpret assembly-like code
NEXT STEPS
  • Study the LMC instruction set, focusing on INP, STA, LDA, ADD, SUB, and BRZ commands
  • Research looping constructs in LMC, particularly using branch commands
  • Examine the "count down to zero" example in the LMC documentation for practical implementation
  • Practice writing LMC programs that utilize loops and conditional branching
USEFUL FOR

Students learning programming concepts, educators teaching assembly language, and anyone interested in understanding the Little Man Computer model for educational purposes.

cduval04
Messages
1
Reaction score
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
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:
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.
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
8K
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
10K
  • · Replies 7 ·
Replies
7
Views
9K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 7 ·
Replies
7
Views
6K