| CompOrg Fall 2002 Homework #1 |
|   Course Syllabus   |   CompOrg Home   |   HW1 FAQ |
| Problem #1 | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
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!.
 
 
| ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
| Problem #2 | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
Do Problem 2.42 from the textbook: "Write a C expression that will
yield a word consisting of the least significant byte of
Notes:
| ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
| Problem #3 | ||||||||||||||||||||||||||||||||||||||||
|   | ||||||||||||||||||||||||||||||||||||||||
|
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
| ||||||||||||||||||||||||||||||||||||||||