program Max /****************************************************************************** * Description: Finds the maximum of a sequence of numbers. * Invalid values of N will cause this program to behave * unexpectedly. * Also, values above 3FFF or below C001 may cause an overflow * error. * Input: N, a(0), a(1), ..., a(N-1) * Output: The largest of the numbers a(0) ... a(N-1) ******************************************************************************/ // Initialize 10: 7101 R[1] <- 0001 11: 82FF read R[2] // Read the first value 12: 83FF read R[3] 13: 2221 R[2] <- R[2] - R[1] // Loop 14: 84FF read R[4] 15: 2534 R[5] <- R[3] - R[4] 16: D518 if (R[5] > 0) goto 18 17: 1340 R[3] <- R[4] 18: 2221 R[2] <- R[2] - R[1] 19: D214 if (R[2] > 0) goto 14 // Print the greatest integer read 1A: 93FF write R[3] 1B: 0000 halt