In: Computer Science
Write a Little Man program that outputs the sum of n number of input values.
CODE FOR THE GIVEN PROGRAM IN LMC(LITTLE MAN COMPUTER) IS:
INP
STA NUMBER
LOOP LDA TOTAL
ADD NUMBER
STA TOTAL
LDA NUMBER
SUB ONE
STA NUMBER
BRP LOOP
LDA TOTAL
OUT
HLT
NUMBER DAT
TOTAL DAT 0
ONE DAT 1
INSTRUCTION SET FOR THE ABOVE LMC IS:
| MNEMONIC | NAME | DESCRIPTION |
|---|---|---|
| INP | INPUT | This is used to retrieve the data from user and stores it in accumulator. |
| OUT | OUTPUT | This is used to display the output or final result in accumulator. |
| LDA | LOAD | This is used to load the accumulator with the contents of memory address. |
| STA | STORE | This is used to store the value in accumulator in memory address given. |
| ADD | ADDITION | This is used to add the contents of memory address to accumulator. |
| SUB | SUBTRACT | This is used to subtract the contents of memory address from the accumulator. |
| BRP |
BRANCH IF POSITIVE |
This is used to jump to the address given if the accumulator is zero or positive. |
| HLT | HALT | This is used to stop the code. |
| DAT | DATA LOCATION | This is used to associate a label to a free memory address. An optional value can also be used to be stored at memory address. |