1. For problems 1-4 below, assume 4-bit words and integers represented in 2's complement form.
A. (6 points) Which of the
following binary numbers are negative?
a.)
1100
b.)
0101
c.) 1001
B. (6 points) Negate the following
numbers:
a.)
0001
b.)
1010
c.) 1001
C. (6 points) Give the binary representation for:
a.)
-7
b.) -1
c.) 7
D. (12 points) Perform the
following operations and indicate, in each case, whether or not overflow
occurs:
a.)
1000
b.)
1000
c.)
1111
d.) 0000
+0001
+1111
-0001
-1111
2. (10 points) An expedition to
Mars found the ruins of a civilization. The explorers were able to translate
the
mathematical equations:
5x² -50x + 125 = 0
with the solutions:
x = 5 and x = 8.
The x = 5 solution seemed okay, but x = 8 was puzzling. The
explorers reflected on the way
in which Earth's number system developed. How many fingers
would you say the Martians had?
3. (15 points) Suppose Venetians use a trinary
number system with their three digits defined as follows:
X
denotes +1
Y
denotes 0
Z
denotes -1
Numbers in their system consist of four trinary digits with the value of the number B3B2B1B0 given
by the expression: 27*B3 + 9*B2 + 3*B1 + B0. For example,
XZYX = 19.
a.) What values does ZYYX represent?
b.) How do
Venetians represent +30?
How do
they represent -30?
c.) How many different values can Venetians represent in their system?
d.) Suppose MAX
is the largest positive integer Venetians can represent in their system. Can
they
represent all integers in the range from 0 to MAX, inclusive? What about from
-MAX to
0,
inclusive?
4. (15 points) Given the following function prototype in C, answer i. – iv. below:
unsigned char Read_Results
(char * pResults, char byArray[],
int pos);
a. What is the size in bytes of the return value of the function? _________
b. What is the size in bytes of each of the parameters passed to the function?
_________ char *pResults
_________
char byArray[]
_________
int pos
c. Write a C statement that reads the data at address (pResults+pos) and assigns it to the element of byArray at position pos.
5. (20 points) Given the C variable declarations, place the variables into memory locations in the table below. Put the name of the variable into any memory location that it uses. Place an X in any unused location.
char a[5];
short b;
short c;
int d;
long e;
short f;
char *g;
Assume that the block of variables is allocated in memory beginning at address 0x30001000. That is, the address of variable “a” is 0x30001000.
Assume
also:
Address |
Each
column is one byte. Thus, a row is a double word. |
|||||||
0x30001000 |
|
|
|
|
|
|
|
|
0x30001008 |
|
|
|
|
|
|
|
|
0x30001010 |
|
|
|
|
|
|
|
|
0x30001018 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i.
How many bytes of memory are used for this block of variables? ______
ii. What is the address of variable “e”? ________________________
iii. What is assigned to variable “g” in each of the following statements?
g = a; _____________________
g = &a[5]; _____________________
6. (10 points) Given the memory dump and
declarations, answer the following questions.
Address
(hex)
Memory Contents (hex)
30005000 00 FE 25 24 5B 1A EE 05
30005008 AC AE 81 83 30 00 32 00
30005010 30 00 50 04 AC CB F0 8D
short a[7];
char b;
short * c;
Assume that the variables a, b and c are allocated in memory beginning at address 0x30005000. That is, the address of “a” is 0x30005000; “b” follows “a” in memory; and “c” follows “b”.
i.
What is the value of *(c
+ 2):
_______________________
ii. What is the value of b after executing the
statement: _______________________
c = &a[3];