2

I'm trying to figure out a way to store the min and max of 10 numbers that are input by the user. I'm not searching through an array of numbers but rather I want to compare each input number that comes in before I add it to the other numbers. The code I made below will add all the input numbers together and then subtract to get the average, but I also want to output the min and max, and I'm not sure how to do that.

The numbers that will be input are: 10 20 30 40 50 60 70 80 90 100.

So currently the code only outputs the average which is 55

ORG 100

LOOP, LOAD X    /counter
SUBT TEN
SKIPCOND 000   /if X = 10
JUMP LOOP2     /take average after X = 10;

CLEAR           /BEGIN INPUTING NUMBERS FOR AVERAGE
INPUT
ADD Y           /add Y to the input
STORE Y         /save new value
CLEAR
LOAD X         /INCREMENT COUNTER
ADD ONE
STORE X
CLEAR
JUMP LOOP       /RESTART LOOP

LOOP2, LOAD Y    /LOAD ALL THE ADDED NUMBERS
SKIPCOND 800     /WHEN Y = 0
JUMP PRINT       /GO TO OUTPUT

SUBT TEN         /SUBTRACT 10 UNTIL REACH 0
STORE Y          /STORE NEW NUMBER
CLEAR
LOAD AVERAGE     /EACH LOOP ADD 1 TO AVERAGE
ADD ONE
STORE AVERAGE
CLEAR
JUMP LOOP2

PRINT, LOAD AVERAGE
OUTPUT

HALT

TEN, DEC 10
ONE, DEC 1
X, DEC 0          /USE TO INPUT 10 NUMBERS, COUNTER
Y, DEC 0          /ALL NUMBERS INPUT ADDED 
MIN, DEC 0       
MAX, DEC 0
AVERAGE, DEC 0    /AVERAGE OF Y DIVIDED BY X
flowinwind
  • 69
  • 1
  • 11
  • 1
    Instead of adding the answer to your question, why don't you post it as an answer and accept it? You can post answers to your own questions on stackoverflow.com. – lurker Dec 17 '15 at 12:21

1 Answers1

0

This solution is taken from the OP's question. (it's been edited out)

LOOP, LOAD X
    SUBT TEN
    SKIPCOND 000   /if X = 10
    JUMP LOOP2     /take average after X = 10;

    CLEAR           /BEGIN INPUTING NUMBERS FOR AVERAGE
    INPUT
    STORE TEMP
    CLEAR

IF, LOAD X
    SUBT 1
    SKIPCOND 800
    JUMP STOREFIRST

    CLEAR
    LOAD TEMP
    SUBT MIN
    SKIPCOND 000
    JUMP FINDMAX

ELSE, SKIPCOND 800
    JUMP FINDMIN

    CONTINUE, CLEAR
    LOAD TEMP
    ADD Y           /add Y to the input
    STORE Y         /save new value
    CLEAR
    LOAD X         /INCREMENT COUNTER
    ADD ONE
    STORE X
    CLEAR
    JUMP LOOP       /RESTART LOOP

    FINDMAX, CLEAR
    LOAD TEMP
    STORE MAX
    JUMP CONTINUE

    FINDMIN, CLEAR
    LOAD TEMP
    STORE MIN
    JUMP CONTINUE

STOREFIRST, LOAD TEMP
    STORE MIN
    STORE MAX
    JUMP CONTINUE

LOOP2, LOAD Y    /LOAD ALL THE ADDED NUMBERS
    SKIPCOND 800     /WHEN Y = 0
    JUMP PRINT       /GO TO OUTPUT

    SUBT TEN         /SUBTRACT 10 UNTIL REACH 0
    STORE Y          /STORE NEW NUMBER
    CLEAR
    LOAD AVERAGE     /EACH LOOP ADD 1 TO AVERAGE
    ADD ONE
    STORE AVERAGE
    CLEAR
    JUMP LOOP2

    PRINT, LOAD AVERAGE
    OUTPUT
    CLEAR
    LOAD MIN
    OUTPUT
    CLEAR
    LOAD MAX
    OUTPUT
    CLEAR

    HALT

TEN, DEC 10
ONE, DEC 1
X, DEC 0          /USE TO INPUT 10 NUMBERS, COUNTER
Y, DEC 0          /ALL NUMBERS INPUT ADDED 
MIN, DEC 0       
MAX, DEC 0
TEMP, DEC 0
AVERAGE, DEC 0    /AVERAGE OF Y DIVIDED BY X