| CompOrg Fall 2003 |
|   CompOrg Home   |   HW#1 FAQ |
| Problem #1 (30 points total) | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
Figure out the missing values in the tables below (all the blank cells). Pay attention to whether items are signed or unsigned, and the number of bits!.
 
 
Sample AnswerAnswers are shown above in gray. 2 points each except the last one (-96.125) is worth 4 points. | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
| Problem #2 (40 points) | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
Do Problem 2.43 from the textbook. Make sure that your answers are valid C expressions using only bitwise logical and logical operators!.
Notes:
Sample Answer10 points each
NOTE: There are certainly other possible correct answers - make sure they use C logical and bitwise logical operators only, not arithmetic or comparison operators! | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
| Problem #3 (30 points) | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
Consider the computer addition of two integers. Both integers are representable as 8-bit 2's complement integers. The result is also an 8 bit 2's complement integer. We know that the true sum may not fit in an 8 bit 2's complement integer - your job is to write some C code that determines whether or not the answer is correct. You can't use any arithmetic that involves anything other than 8 bit 2's complement numbers, but you can use logic operations. Show some C code that will print "yes" if the computed sum is correct (the correct answer fits in an 8 bit 2's complement int) or prints "no" if the answer is wrong (the sum cannot be represented as an 8-bit 2's complement int). Here is what the code might look like, with the sections you must
write left out. NOTE:
/* x and y already have some values at this point */
z = x + y; /* z now has 8 bit result. Is it right? */
if (...you need to write this...) {
printf("yes");
} else {
printf("no");
}
NOTE: Feel free to write it any way you want,
you don't have to do the entire job with a single HINTS: Review the conditions under which the result of 2's
complement computer addition is not correct (page 70 in the text). You
need to find a way to express these conditions in C, without using
arithmetic (use logic operations - look at the bits of
Sample Answer
if ( (( x & 0x80)!=(y & 0x80)) || ( (z & 0x80) == (y & 0x80)) ) {
printf("yes");
} else {
printf("no");
}
Grading:
Any solution that relies on arithmetic should lose 10 points. NOTE: There are many correct ways of doing this (some people will notice that using XOR can be useful here). They are allowed to use multiple if statements. They are not allowed to use integer arithmetic (so they can't just compare the 8 bit result to a 32 bit result). They must use bitwise logic and/or boolean logic operators! | ||||||||||||||||||||||||||||||||||||||||