COSC4307			TEST-3			8/15/2003

NAME__________________________________________

PART-A. Multiple Choices				(80 points)
Choose exactly one answer in each question by writing down your choice 
letter in CAPITAL.

For questions 1-4, consider the following Boolean expression and a sequence 
of quadruples that can be generated: 	
You must assume the usual operator precedence.

	A OR NOT(B  OR  C AND D)

	100:	=,	#1,	0, 	T5
	101:	BB,	A,	X0,	102
	102:	BB,	B,	X1,	X2
	103:	BB,	C,	X3,	X4
	104:  	BB,	D,	X5,	X6
	105:	=,	#0,	0,	T5
	106:	BEQ,	X7,	#0,	???

1.	The value of X1 and X5 are, respectively
	a. 	103 and 106		b. 	104 and 104		
 (C)	c. 	Neither          
                                                       
2.	The value of X2 and X6 are, respectively:
 (C)	a. 	103 and 104		b. 	105 and 105		
	c. 	Neither
3.	Which two values are the same?
 (C)	a.	X4 and X0		b. 	 X4 and X6		
	c.	Both            	d.       Neither
4.	The value of X7 is
 (A)	a.	T5			b.	104			
	c.	neither

5.	        INDIRECT, T4, 0, T5
 (C)         	=,        T4, 0, T5
	The main difference between the two above is in 
	a.	how the value of T4 is used..
	b.	whether T5 gets a new value or it gets a pointer set up pointing to its memory address.
	c.	Both.			d.	neither
6.	Backpatching involves
 (C)	a.	Unfinished quadruples at the time of their generation.
	b.	Branch quadruples.
	c.	both.				d.	neither.

		void E(int & Loc)	// E -> T {+T}*
7.	As given in class, quadruples DIRECTLY generated by above function include:
 (B)	a.	INDIRECT
	b.	+
	c.	*
	d.	All above		e.	Two above			f.	None above
8.	In translating Boolean expressions, each time the "AND" operator is scanned,
 (A)	a.	the current True-link has just been resolved.
	b.	the current False-link has just been resolved.
	c.	cannot tell			d.	it can be either.
9.	Which are PC's general-purpose registers?
 (A)	a.	AX and BX
	b.	SP and BP
	c.	both				d.	neither
10.	Which is a segment of PC assembly program?
 (D)	a.	Code segment			b.	Stack segment
	c.	Data segment			d.	All			e.	Two
11.	Which general-purpose register is  mostly involved in arithmetic instructions
 (A)	such as IMUL or MUL?
	a.	AX		b.	BX			
	c.	BP		d.	cannot tell.

		INDIRECT,	T5,   0,  T6
12.	In translating above quadruple, which addressing mode is the most suitable?
 (C)	a.	direct		b.	immediate data
	c.	indexed		d.	cannot tell,

For the next four questions, refer to the following array declaration:
	A[1:10, 1:20, 1:40]		
		//Note the lower bound of each dimension is 1.
		//Also that each array element occupies just one memory space.

13.	For the Row Major sequence,  VarPart(Offset(A[i,j,k])) is
 (B)	a.	(k-1) + (j-1)*40 + (i-1)*800
	b.	k + j*40 + i*800
	c.	Neither
14.	For the Column Major sequence, Offset(A[i,j,k]) is
 (A)	a.	(i-1) + (j-1)*10 + (k-1)*200
	b.	i + j*20 + k*800
	c.	Neither.
15.	For the Row Major sequence, each time the first subscript is increased by one 
 (C)	with all other subscripts remaining the same, the address increases by
	a.	8000 array elements.
	b.	200 array elements.
	c.	800 array elements. 
	d.	None.
16.	Which array element has a smaller VarPart of its offset when the Row Major sequence is used 
 (A)	than when the Column Major sequence is used?
	a.  A[1,1,30]		b. A[10,1,1]		c. Both.		
	d. Neither.

For the next four questions, refer to the following grammar:
		BE -> 	BT    |   TOR  BE
		TOR ->	BT  OR
		BT->	BF    |   FAND  BT   
		FAND ->	BF  AND
		BF ->	id    |   ( BE )   |  NOT BT

 17. 	According to the grammar, both AND and OR are
 (B)	a. Left-associative		b. Right-associative.		
	c.  Cannot tell

 18.	Which has the lowest operator precedence according to the grammar?
 (C)	a.  NOT		b.   AND	c.  OR		d. Cannot tell

 19.		NOT A  AND B
 (D)	According to the grammar, above is necessarily the same as:
	a.	NOT (A  AND B)
	b.	NOT(A)  AND   B
	c.	both.			d. 	neither
 20.		A  OR B  AND C
 (A)	According to the grammar, above is necessarily the same as:
	a.	A OR (B AND C)
	b.	(A OR B) AND C
	c.	Neither.		d. 	Cannot tell

PART-B.  Other Problems.					(20 points)

Do two problems in this PART-B.

A.   	In no more than 8 lines, state some design issues of code generation.

B.	Give a sequence of statements (i.e., a semantic routine) to generate 
	quadruples for a WHILE Loop of the form:
		S -> While (E) do S endwhile	
			// The loop iterates as long as 
			// the given expression is Non-Zero

	NOTE:	1. In the above rule, only S and E are a nonterminal, each.
		2. You can assume the availability of a function, E(int & Loc),
		   that translates an expression and returns a memory 
		   location to contain the final value of the expression 
		   being translated.

C.	Complete the following C++ function that resolves a given link field 
	that is the first one of any number of links merged/linked together.

	void Fillin (int field)
	  // Note that the given (starting) field may be negative or positive.