231 Spring 2011 -- Exam 2 Name: _________________
No calculators. Questions add to 114 points to allow for extra credit.
You will be graded out of 100 points.
1. Convert these numbers between signed decimal and 16-bit two's complement
representation. (5 pts. each)
signed decimal two's complement
a. +155 ________
b. ________ 0x0155
c. -155 ________
d. ________ 0xff55
2. Give the most negative 12-bit two's complement number in two formats:
(4 pts. each)
a. hexadecimal representation (two's complement): ____________
b. decimal representation: ____________
3. Give the most positive 12-bit two's complement number in two formats:
(4 pts. each)
a. hexadecimal representation (two's complement): ____________
b. decimal representation: ____________
4. Show the hexadecimal results of binary addition and subtraction of signed
16-bit two's complement numbers. Identify any signed overflows. (5 pts. each)
a. 0x7654 b. 0x7654
+0x1abc +0xffed
------- -------
5. Show the hexadecimal results of logic operations on 16-bit binary numbers.
(4 pts. each)
a. 0x7654 b. 0x7654 c. 0x7654 shift d. 0xcdef shift
or 0xcdef and 0xcdef left by 1 right logical by 2
--------- ---------- ------------ ------------------
6. Give a sequence of SPARC shift and add instructions to multiply the value
in register %o0 by 20 decimal and place the result in register %o1. You
may use registers %o2 and %o3 as temporaries. (Do not call .mul) (6 pts.)
7. Give a sequence of SPARC shift and or instructions to rotate the value
in register %o0 by 8 bits to the left and place the result in register
%o1. You may use registers %o2 and %o3 as temporaries. (As one example,
if %o0 contains 0x12345678, the result in %o1 should be 0x34567812.
However, your answer must work for any given value in %o0.) (6 pts.)
8. Give two examples of synthetic instructions and identify the generated
SPARC machine instruction. (4 pts.)
9. Show the big-endian and little-endian byte ordering of the following data
values. Start the byte numbering of t[] at address 100. (8 pts.)
char t[4] = {'a', 'b', 'c', '\0'};
short int u = 0x123; /* short int is 16-bit half word */
short int v = 0x45;
byte address: 100 101 102 103 104 105 106 107
big-endian ordering: ___ ___ ___ ___ ___ ___ ___ ___
little-endian ordering: ___ ___ ___ ___ ___ ___ ___ ___
10. Show the HARDWARE steps required in multiplication of two unsigned
4-bit binary numbers, 1110 times 1011. (1110 is the multiplicand and
1011 is the multiplier.) The details of mulscc are not required, but
you should show the 3-register format of ACC, MQ, and MDR, and be sure
to place the multiplicand and multiplier in the correct registers.
(12 pts.)
11. Show the SPARC code for the following program segment. (12 pts.)
d = d << 8; You may assume these register defines:
for( i=0; i<8; i++ ){ define(a_r,l0)
a = a << 1; define(d_r,l1)
a = a - d; define(q_r,l2)
if( a<0 ){ define(r_r,l3)
a = a + d;
}else{ Add others as needed. You may use %g1
a = a + 1; and/or %o0-%o5 as temporary registers.
}
}
q = a & 0xff;
r = (a>>8) & 0xff;
12. Explain what the code segment in question 11 does. (4 pts.)