How could I go about finding the maximum, minimum and average of a list in assembly language (68000)

228 Views Asked by At

I wrote a function in 68000 assembly that prompts the user to enter the size of a list then prompts them to enter each number and store it in the list. Function screenshot.

Now I want to write a second function to "search" through the list to find the maximum, minimum and average values of the list and store them. I know how to go about it in other languages with certain algorithms, but I can't figure out how to compare each value to find what I am looking for and just need someone to point me in the right direction.

1

There are 1 best solutions below

5
tofro On

You already have a piece of code that walks the list (which is rather an array in your case). Some pseudo code could be

    lea.l      aX,startOfList
    clr.b      dA                ; register dA holds largest so far
    move.b     #255,dB           ; register dB holds smallest so far
    clr.B      dC                ; register dC holds running average
loop:
    cmp.b      (aX),dA           ; is current bigger than everything else?
    blt.s      noBigger          ;
    move.b     (aX),dA           ; remember current as biggest
noBigger:
    cmp.b      (aX),dB           ; is current smaller than smallest so far?
    bgt.s      noSmaller         
    move.b     (ax),dB
noSmaller:
    move.b     (aX)+,dE          ; fetch a temporary
    ext.w      dE                ; make it a word
    bsr        average           ; and build a running average

    bra loop

Note the loop counter (you already have that in your input code) is not shown here, that would be an exercise of your own. The code works by initializing the registers holding the minimum value with the maximum possible and the maximum with the minimum possible, then checking for each entry whether the current one is bigger/smaller than the biggest/smallest so far and replacing it, if yes.