I am working at this coding challenge:
Write a program for the Little Man Computer that allows the user to manage a list of values. It should start with an empty list and then process input as follows:
If the input is:
- less than 100: add this value to a list, unless the list already has 10 values, in which case the value is ignored
- 995: make the list empty
- 996: output the number of values the list currently has
- 997: output each value the list currently has, in the order they were added to it
- 998: output each value the list currently has, in reversed order
- 999: end the program
- Any other value is ignored
The processing of input values continues as long as the input value is not 999.
I'm having issues getting the code to print the stored list in forward order when 997 is input. I think I may have the ADD
and SUB
instructions confused. I also can't get the stored list to reset correctly when 995 is input.
Everything else I was able to program correctly.
Below is my code:
START INP
STA TEMP
SUB NINES
BRZ end
LDA TEMP
SUB EIGHT
BRZ PRIT
lda temp
sub seven
brz printf
LDA TEMP
SUB SIX
BRZ DOOUT
LDA TEMP
SUB FIVE
BRZ RESET
LDA COUNT
SUB TEN
BRZ START
LDA TEMP
SUB HUND
BRP START
SIT LDA SINST
ADD COUNT
STA SLOC
LDA TEMP
SLOC DAT 0
LDA COUNT
ADD ONE
STA COUNT
BRA START
PRIT LDA COUNT
BRZ END
PRINTR LDA LINST
ADD COUNT
SUB ONE
STA LDIT
LDIT DAT 0
OUT
LDA COUNT
SUB ONE
STA COUNT
BRZ END
BRA PRINTR
---PRINTF LDA LINST
ADD COUNT
add ONE
STA LDIT
LDIT DAT 0
OUT
LDA COUNT
SUB ONE
STA COUNT
BRZ END
BRA PRINTF
doout lda count
out
bra start
reset lda zero
sta count
bra start
END HLT
TEMP DAT 0
COUNT DAT 0
ONE DAT 1
TWO DAT 2
TEN DAT 10
HUND DAT 100
SINST DAT 380
LINST DAT 580
five dat 995
six dat 996
seven dat 997
eight dat 998
NINES DAT 999