Concepts in Computing
CS4 - Winter 2007
Instructor: Fabio Pellacini

# HW 6, due Wednesday, Feb 28

## Instructions

This homework is comprised of a set of written questions. You are not required to write your answers in HTML. However, you should still upload them to your private directory and provide a printout. Upload your file in a format we can read -- plain text, HTML, PDF, Word, or RTF. No timestamp is required.

In this homework, you will be using binary numbers. Use 8 bits for integer number using the two's complement representation and 16 bits floating point numbers (10 bits mantissa, 6 bits exponent) where mantissa and exponent are represented in the complement of two representation.

## Written Problems

1. Decimal to Binary Conversion [10 points]
Convert the decimal numbers 20 and -30 to binary. Explain how you did it (you can use the procedure in the lecture notes; note that it was not covered in class). Also convert the number 12.8 to floating point binary.
2. Binary Sum and Binary to Decimal Conversion [15 points]
Sum the binary numbers 01100110 and 00010110. Show the carry bits. Verify that the sum is the same as summing the numbers in decimal, by computing the decimal value of each number and their sum (show how to perform the conversion by using sum of products of digits times powers of two as done in class).
3. Numerical Precision [10 points]
Suppose you have two binary numbers 01000000 and 01000000. What error would happen if you were to sum them? Also what numerical errors to you expect if you use floating point to represent pi?
4. Encoding Strings [5 points]
Write the first four letters of your name in binary. To do so, convert the letter to binary numbers using the ASCII table in this Wikipedia article. This is the representation for "strings" used by the C programming language: essentially a tring of text is nothing else than an array of (small) integer numbers.
5. Truth Table [5 points]
Write the truth table for a binary function of two arguments that is true if and only if each of the argument is false. This is equivalent to `!(A || B)`.
6. Circuits [10 points]
Using the construction procedure given in class, build a circuit to perform the operation described in the following truth table.
001
010
100
111
7. Machine Model [10 points]
Consider a machine that uses 6 bits for the instruction opcodes and 10 bits for the arguments. How many different instructions are possible? How many different memory locations can it access?
8. Translating Code [15 points]
Write the following pieces of code in the assembly language covered in class (and in the textbook). Your code should use labels and .DATA pseudo-ops to define the locations of the variables and jump targets. Use `OUT` to traslate `print`, `IN` for `read` and `HALT` for `return`.
``````
x = y+1;
if (x < 1) { print( x ); } // output x and halt
else { print( 1 ); }
return;
``````
9. Translating Code [20 points]
Write the following pieces of code in the assembly language covered in class (and in the textbook). Your code should use labels and .DATA pseudo-ops to define the locations of the variables and jump targets. Use `OUT` to traslate `print`, `IN` for `read` and `HALT` for `return`.
``````