Homework 2

22C:18, Summer 1997

Due Friday June 20, 1997, in class

Douglas W. Jones

  1. Translate the following Hawk instructions to machine code, giving the result as a string of consecutive halfwords in hex:
    	LIS	R1,#FF
    	LIL	R2,#FEDCBA
    	ORIS	R2,#98
    	ADD	R3,R2,R1
    
  2. 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"
    	S	start
    
    start:
    	LIS	R1,#FF
    	LIL	R2,#FEDCBA
    	ORIS	R2,#98
    	ADD	R3,R2,R1
    	LOAD	R4,pointr
    	STORES	R3,R4		; store in data
    
    	LIW	R5,#FF000100
    	LIW	R6,"OLEH"
    	STORES	R6,R5
    
    	H	0
    
    	ALIGN	4
    	COMMON	data,4
    pointr:	W	data
    
    	END
    

  3. What value does the instruction sequence given above leave in each register and in the memory location named data?

  4. Given that R3 holds x, a 32 bit signed number in the 2's complement system, write a short sequence of SMAL Hawk instructions to compute abs(x) (the absolute value of x).

  5. Assuming that all variables are 32 bit integers, and that the registers R5, R6 and R7 are used to hold the variablex x, y and z, respectively write a sequence of SMAL Hawk assembly language instructions that is equivalent to the following sequence of Pascal instructions:
        z := 0;
        y := 1;
        repeat
    	x := z + y;
    	y := z;
    	z := x;
        until x > 50
    
    (In Pascal, := means assignment, = means comparison for equality; beyond those details, everything else about the above code should be intuitive.) You need not run this program! You may run it; 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!