Homework 3

22C:18, Fall 1996

Due Tuesday Sep. 17, 1996, in discussion

Douglas W. Jones
  1. Use the SMAL assembler to produce a printed assembly listing of the following, with the title changed to give your name and your section number, instead of D. W. Jones and section A:
    	TITLE	D. W. Jones 22C:018-A HW3
    	USE	"/group/22c018/hawk.macs"
    .	=	#1000
    	S	start
    
    start:
    	LIL	R1,data
    	LOADS	R2,R1
    	LOAD	R3,R1,4
    	ADDS	R3,R3,2
    	ADDS	R3,0,1
    	ADD	R4,R3,R2
    	STORES	R4,R1
    
    .	=	RAM
    data:	W	50	; the variable a
    	W	50	; the variable b
    	END
    

  2. What value does the instruction sequence given above leave in the memory location with the label data?

  3. Given that the low word of R3 holds x, a 32 bit value, write a short sequence of SMAL Hawk instructions to compute abs(x) (the absolute value of x).

  4. Assuming that all variables are 32 bit integers, and that the registers R1, R2 and R3 are used to hold the variablex x, y and z, write a sequence of SMAL Hawk assembly language instructions that is equivalent to the following sequence of Pascal instructions:
        x := 0;
        y := 1;
        repeat
    	z := x + y;
    	y := x;
    	x := z;
        until z > 100
    
    (In Pascal, := means assignment, = means comparison for equality; beyond this, the above code uses nothing that shouldn't be intuitive.) You need not run this program, but you may; single stepping through the loop until it terminates can be instructive, and this problem counts twice as much as the previous problems on this assignment!