To find the Maximum Value
Purpose:
To find the largest element in a series of 16-bit binary numbers. The length of the series is held in the variable length at location 6000 and the starting address of the series is in the long word variable start at location 6002. The maximum is to be stored in the variable maxnum at location 6006.
[Note that in the specification given above, there is no mention of the lengths of the variables length and maxnum. It is reasonable to suppose that the length will be 16 bits since this is the standard word length of the 68000. In other words the variables are neither small, only one byte (8 bits) nor are they large, four bytes (32 bits)]
Sample Test Data:
input:
length: (6000) = 0004
start: (6002) = 00005000
(5000) = A48E
(5002) = 71AC
(5004) = 34F1
(5006) = E57A
output:
maxnum: (6006) = E57A, since this is the largest of the four numbers.
Source Code:
data | equ | $6000 | |||
program | equ | $8000 | |||
org | data | ||||
length | ds.w | 1 | ;number of data elements | ||
start | ds.l | 1 | ;address of data elements | ||
maxn | ds.w | 1 | ;max number in series | ||
org | program | ||||
movea.l | start, a0 | ;initialise pointer | |||
moveq | #0, d0 | ;max <- 0 | |||
move.w | length, d1 | ;initialise element count | |||
loop | beq.s | done | ;if length = 0 then done | ||
move.w | (a0)+,d2 | ;temp <- next data element | |||
cmp.w | d2, d0 | ;compare temp with max | |||
bcc.s | looptest | ;if max >= temp then jump over replacement |
move.w | d2, d0 | ;new max found | |
looptest | subq.w | #1, d1 | ;update element count |
bra | loop | ;if count not zeo keep going | |
done | move.w | d0, maxn | ;store maximum number in series |