/*
 * CS201: Data Structures
 * Assignment 4 Part II
 *
 * File       : ramprog.txt
 * Description: RAM Program to test RAM implementation.
 *              The program finds out the maximum of the integers
 *              read from the input-tape.  The input-tape
 *              consists of a count (number of input integers)
 *              followed by the integers themselves.  The program
 *              outputs a single integer on output-tape, the
 *              maximum of the input integers.
 *
 *              The program keeps the maximum integer in c(2) and
 *              the loop variable (count) in c(1).
 *
 *              Error checking is not done so as to keep the
 *              program short.  So be careful with the contents
 *              of input-tape while running the program.
 *
 *              Known bugs or features :):
 *                 The program will fail if the input array has
 *                 less than 2 elements.
 *
 * Department of Computer Science and Engineering,
 * Indian Institute of Technology, Guwahati.
 * India.
 *
 * Dated: 20 Aug, 2002.
 */


Add. Label       Instruction        Code     Comments

 0   Start:      READ   0           7  0  0  ;Read count
 1               SUB   =1           4  1  1  ;Decrement it
 2               STORE  1           2  0  1  ;Store it in c(1)
 3               READ   2           7  0  2  ;Put first int in 'max'
 4   Loop:       READ   0           7  0  0  ;Read next int
 5               SUB    2           4  0  2  ;sub max from it
 6               JGTZ   UpdateMax  10  0 13  ;if int>max, max=int
 7   Continue:   LOAD   1           1  0  1  ;Decrememnt count
 8               SUB   =1           4  1  1  ;
 9               STORE  1           2  0  1  ;
10               JGTZ   Loop       10  0  4  ;
11               WRITE  2           8  0  2  ;Write out max
12               HALT              12  0  0  ;End of program

13   UpdateMax:  ADD    2           3  0  2  ;Add max to c(0) to
                                             ;restore the int read
14               STORE  2           2  0  2  ;Store new max
15               JUMP   Continue    9  0  7  ;continue with loop


Hence the program (n*3 array) will be as follows

7 0 0
4 1 1
2 0 1
7 0 2
7 0 0
4 0 2
10 0 13
1 0 1
4 1 1
2 0 1
10 0 4
8 0 2
12 0 0
3 0 2
2 0 2
9 0 7

Sample input (on input tape):

5 10 -3 5 20 9

Sample output (on output-tape):

20