I am looking at this Little man computer problem:
The user will enter first the size of the data, and then the individual numbers.
I have to print (
OUT
) excatcly what was input, followed by the max and the min of the data values
Example:
- First input: 2 // Number of DATA
- Second input: 5 // First DATA
- Third input: 7 // Second DATA
- Output: 2, 5, 7, 5(min), 7(max)
I have to print everything at the end (when the user finished to enter all the inputs)
My attempt:
IN # Acc = number of values to read (N)
STO M
LOOP BRZ PRG
SUB ONE
STO N # N=N-1
IN # values
ST STO PRG # Store it in the program starting at PRG
LDA ST # Get current store command (ST)
ADD ONE # add one to store command to increment memory location
STO ST # Update store command (ST)
LDA N # Put current value of N in accumulator
BRZ PRINT
BRP LOOP # Continue loop - 12
#My problem is here
PRINT LDA M
OUT
LDA PRG
OUT
FIN HLT
M DAT 0
N DAT 0 # Number of values to read
ONE DAT 1 # Value 1
PRG DAT 0 # We will store all of the values from this point onward
Question
I tried to get this solved, but as you can see, I only succeeded to print the first value. I also saved my inputs in memory, but how can I loop on the address to get the values for output?