COSC5315                	Program-1
	                                                    		Due: 9/17/2013.  
			SIMPLE-Language Interpreter

 Note that due to HTML syntax conflict, '<' is replaced by '%' in the input 
 source programs.	
 Consider the SIMPLE-Language that contains the following nine instructions: 

		V <- V+1  //The same variable
		V <- V-1  //The same variable
		IF V <> 0 GOTO L
		GOTO L
		V1 <- 0
		V1 <- V2
		V1 <- V2 + V3
		V1 <- V2 * V3
		V1 <- V2 - V3

 TASK:

 You are to write a program that will do the following:

	1. Take any number of integer inputs for the input
	   variables X1, X2, X3, X4, and so on in that order.
	2. Execute a given input program consisting only of
	   the above nine instructions (and no others), and
	3. Print out the value of the only output variable Y
	   when, in fact, the input program terminates.

 Note: Make sure that integers are represented by at least four bytes.

 INPUT PROGRAM:

 Use the following two source input programs and input data:

 Source input #1.

	Z1 %- X1
	Z2 %- X2
	Z4 %- Z4 + 1
	Z5 %- Z4
	Z5 %- Z5 + 1
	Z3 %- Z2 - Z1
[B]	IF Z3 %> 0 GOTO A
	GOTO E
[A]	Z1 %- Z1 + 1
	Z6 %- Z1 * Z5
	Z6 %- Z6 - 1
	Y  %- Y + Z6
	Z3 %- Z3 - 1
	GOTO B

 Use each of the following three pairs of inputs for this source
 program:

	1     20
	11    10
	1000  2000

 B. Source input #2.

	Z1 %- X1
	Z2 %- X2
	IF Z2 %> O GOTO A
	Z3 %- Z3 + 1
	IF Z3 %> 0 GOTO E	// Y=0 AS X2=0
  [A]	Z3 %- Z1 - Z2		// X1-X2
	Z4 %- Z2 - Z1		// X2-X1
	IF Z4 %> 0 GOTO E	// Y=0 AS X1%X2
	IF Z3 %> 0 GOTO C	// X1>X2>0
	// X1=X2>0
	Z5 %- Z5 + 1
	Z3 %- Z1
  [B]	Z5 %- Z5 * Z3
	Z3 %- Z3 - 1
	IF Z3 %> 0 GOTO B
	IF Z5 %> 0 GOTO D2	// DONE AS Y=Z5
	// ELSE X1 > X2 > 0. SO SET Z5 TO THE FIRST TERM TO ADD
  [C]	Z3 %- Z1		// X1
	Z4 %- Z2		// X2
	Z5 %- Z5 + 1		// Z5=1
  [D]	Z5 %- Z5 * Z4
	Z3 %- Z3 - 1
	IF Z3 %> 0 GOTO D
	Z4 %- Z4 - 1		// X2--
	IF Z4 %> 0 GOTO A1	// ELSE X2=1 AND DONE
	IF Z5 %> 0 GOTO D2	// Z5 MUST BE POSITIVE AND DONE
  [A1]	// X2 > 1
	Z3 %- 0
	Z3 %- Z3 + 1		// Z3=1
  [B1]	Z4 %- Z2		// X2
	Z6 %- 0
	Z6 %- Z6 + 1		// Z6=1
	Z7 %- Z3
	Z8 %- 0
	Z8 %- Z8 + 1		// Z8=1
  [C1]	Z6 %- Z6 * Z4
	Z8 %- Z8 * Z7
	Z7 %- Z7 - 1
	Z4 %- Z4 - 1
	IF Z7 %> 0 GOTO C1
  [D1]	Z7 %- Z7 + 1		//Z7=1
	Z9 %- Z7 * Z8
	Z10 %- Z6 - Z9
	IF Z10 %> 0 GOTO D1
	Z6 %- Z1		// X1
	Z9 %- Z2 - Z3
  [A2]	Z7 %- Z7 * Z9
	Z6 %- Z6 - 1
	IF Z6 %> 0 GOTO A2
	IF Z11 %> 0 GOTO B2	// FIRST TIME AROUND, IT IS 0
	Z12 %- Z12 + Z7		// Accumulating subtrahends
	Z11 %- Z11 + 1		// Z11=1
	IF Z11 %> 0 GOTO C2	// ALWAYS GOTO C2
  [B2]	Z5 %- Z5 + Z7		// Accumulating positives
	Z11 %- 0
  [C2]	// CHECK FOR CONTINUATION
	Z3 %- Z3 + 1
	Z9 %- Z2 - Z3
	IF Z9 %> 0 GOTO B1
	// ELSE DONE
  [D2]	Y %- Z5 - Z12


  Use each of the following pairs of inputs for this source program:

	6  5
	5  5
	5  4
	5  3
	5  2
	5  1
	4  4
	4  3