Shop OBEX P1 Docs P2 Docs Learn Events
Assembly Averaging — Parallax Forums

Assembly Averaging

scottascotta Posts: 168
edited 2007-03-05 18:48 in Propeller 1
I have 5 numbers in 5 RES variables.

A1
A2
A3
A4
A5

How do I toss the high and low values, then average ?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-30 03:54
    Define new RES variables "MaxVal", "MinVal", and "Total" and do:
       mov  MaxVal,A1   ' This can be made into a loop with
       mov  MinVal,A1   ' any number of variables, but this
       mov  Total,A1   ' is simpler when only a few variables
       add   Total,A2   ' are used
       min   MaxVal,A2
       max  MinVal,A2
       add   Total,A3
       min   MaxVal,A3
       max   MinVal,A3
       add   Total,A4
       min   MaxVal,A4   ' Note that this wouldn't necessarily
       max  MinVal,A4   ' be what you want if two or more
       add   Total,A5   ' values were the high or low values
       min   MaxVal,A5
       max  MinVal,A5
       sub   Total,MaxVal   ' Toss the high and low values
       sub   Total,MinVal   ' and divide by 3 to get average
       mov  MaxVal,#3   ' Reuse MaxVal and MinVal since
       shl   MaxVal,#14   ' they're not needed further
       mov   MinVal,#16
    :divide cmpsub Total,MaxVal    wc
       rcl   Total,#1   ' See document called Propeller Guts
       djnz   MinVal,#:divide   ' Result is left in "Total"
    
    

    Post Edited (Mike Green) : 3/5/2007 6:49:02 PM GMT
  • scottascotta Posts: 168
    edited 2007-03-05 16:58
    Your brain sees problems differently than mine does. It takes me 10 minutes to read
    something like this before it clicks.

    Sorry I didn't get back to you on this sooner.

    Thanks,

    Scott
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-05 17:23
    There are a couple of things going on there
    1) Accumulating a total of the points
    2) Determining the maximum of the points
    3) Determining the minimum of the points
    4) At the end: Divide the total by the # of points
    So:
    1) At the beginning, we initialize MaxVal, MinVal, and Total to the 1st value
    2) For each subsequent point (A2 - A5), we add it into the Total, use the max
    instruction to determine the minimum value (I know it seems backwards,
    but there it is ... It does work this way ... Look carefully at the instruction
    description) and the min instruction to determine the maximum value.
    3) There's a simple division by a constant (the number of points). Note that
    I messed up with the constant value. It should be 5, not 3.
    Mike
  • Lord SteveLord Steve Posts: 206
    edited 2007-03-05 18:43
    Mike Green said...
    I messed up with the constant value. It should be 5, not 3.
    Did I miss something?· If you have 5 values and you toss the minimum and maximum values...you have 3 left over.· So, the average of 3 values is the sum divided by...3, not 5.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-05 18:48
    Lord Steve,
    Thanks. You're absolutely correct. I forgot about the "tossing the max and min values". Oh well, I guess I'm more confused than usual today.
    Mike
Sign In or Register to comment.