Starting from:

$25

CIS450 -hw1 - Solved

 Computer Organization and Architecture 

 

1. (2.43/2.61) – Using only bit-level and logic operations, write C expressions that yield 1 for the described condition, and 0 otherwise. Assume that x is of type int. You may not use any equality (= =) or inequality (!=) tests. 

  

a.       Any bit of x equals 1. _______________________________________________

 

b.      Any bit of x equals 0. _______________________________________________

c.       Any bit in the least significant byte of x equals 1. _________________________

d.      Any bit in the least significant byte of x equals 0. _________________________

Hint: One solution to part (a.) is: !!x (and, yes, you can use this as your solution :-).

 

 

2. (2.81) – Write C expressions to generate the bit patterns that follow, where ak represents k repetitions of symbol a. Assume a w-bit data type. Your code may contain references to j and k, representing the values of j and k, but not a parameter representing w.  

 

a.       1w-k 0k

b.      0w-k-j 1k 0 j

 

For example, if we are dealing with chars, an 8-bit data type, and k = 3, then for a. we want an expression that results in 11111000.

 

 

 

3. (2.50/2.76/2.77) – Suppose we are given the task of generating code to multiply integer variable x by various different constant factors K. To be efficient, we want to use only the operations +, -, and <<. For the following values of K, write C expressions to perform the multiplication using at most three operations per expression.

 

 

a.       K = 31:            ________________________________________________________

b.      K = -7:             ________________________________________________________

c.       K = 80:            ________________________________________________________

d.      K = 144: ________________________________________________________

 

Hint: One solution to part (a.) is: (x<<5) - x. 

 

 

 

 

 

4. (2.55/2.82/2.83) – Consider the numbers having a binary representation consisting of an infinite string of the form 0.yyyyyy…, where y is a k-bit sequence. For example, the binary representation of 1/3 is 0.0101010101… (that is, y = 01, and k = 2), while the representation of 1/5 is 0.001100110011… (that is, y = 0011, and k = 4).

a.       Give a formula in terms of y and k for the value represented by the infinite string. Hint: Consider the effect of shifting the binary point k positions to the right, and do part b. first…

 

 

 

b.      What is the numeric value of the string for the following values of y? Note that the value of k is implied; e.g., for case i., k = 3, etc.

 

i. 110 ____________________________________________________ ii. 01001 ____________________________________________________ iii. 010111 ____________________________________________________

 

5. Consider a 16-bit two’s complement representation for signed integers. Fill in the empty boxes in the following table. Spaces in the binary representation are just added to enhance readability. 

 

 

Number 
Decimal Representation 
Binary Representation 
 zero 

 
 
 
0000 0000 0000 0101 
twenty five 
25 
 
TMax 
32767 
 
TMin 
 
1000 0000 0000 0000 
TMin + TMin 
 
 
-TMax 
 
 
-TMin 
 
 
 
 
1111 1111 1110 0111 
negative one 
-1 
 
                               Show work. Hint: 215 = 32768, 214 = 16384, .. , 25 = 32, 24 = 16, .. , 21 = 2, 20 = 1 

 

                                            

More products