-
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
0000: D1FF LIS R1,#FF
0002: E2FE LIL R2,#FEDCBA
0004: DCBA
0006: C298 ORIS R2,#98
0008: 3321 ADD R3,R2,R1
-
Use the SMAL assembler to produce a printed assembly listing like this:
SMAL32, rev 6/97. D. W. Jones 22C:018-A HW3 08:17:02 Page 1
Tue Jun 24 1997
1 TITLE D. W. Jones 22C:018-A HW3
2 USE "/group/22c018/hawk.macs"
3 S start
4
5 start:
6 LIS R1,#FF
+000000: D1FF 7 LIL R2,#FEDCBA
+000002: E2FE DCBA 8 ORIS R2,#98
+000006: C298 9 ADD R3,R2,R1
+000008: 3321 10 LOAD R4,pointr
+00000A: F4E0 0012 11 STORES R3,R4 ; store in d
+00000E: F324 12
13 LIW R5,#FF000100
+000010: E5FF 0001 14 LIW R6,"OLEH"
C500
+000016: E64F 4C45 15 STORES R6,R5
C648
+00001C: F625 16
+00001E: 0000 17 H 0
18
19 ALIGN 4
20 COMMON data,4
+000020:+00000000 21 pointr: W data
22
23 END
no errors
-
What value does the instruction sequence given above leave in
each register and in the memory location named data?
PC: 0000101E R8: 00000000
PSW: 0000FF09 R1: FFFFFFFF R9: 00000000
NZVC: 1 0 0 1 R2: FEDCBA98 RA: 00000000
R3: FEDCBA97 RB: 00000000
R4: 00010000 RC: 00000000
R5: FF000100 RD: 00000000
R6: 4F4C4548 RE: 00000000
R7: 00000000 RF: 00000000
R4 points to data; M[R4] = M[#10000] = R3 = FEDCBA97
-
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).
TESTR R3
BNR pos
NEG R3,R3
pos:
-
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:
CLR R7 ; z := 0;
LIS R6,1 ; y := 1;
LOOP: ; repeat
ADD R5,R7,R6; x := z + y;
MOVE R6,R7 ; y := z;
MOVE R7,R5 ; z := x;
CMPI R5,50 ; until x > 50
BLE LOOP
The most important and common problem students had with the above is
recognizing that the loop termination condition is tested after the
execution of the loop body (the same is true with the C/C++ do-while
loop).