# Lab 10

Overview: Computer Organization: Binary number representation, Boolean logic, circuits and gates, machine language.

## Problems

1. Consider the machine instruction `10001000000000010001`, where `10001` is an opcode indicating the STORE X command, meaning to copy the contents of the register R to memory address X.

1. What is the maximum number of instructions that could be in the instruction set of this machine? Why?
2. How many memory cells (addresses) does the computer have? Why?
3. How big are the registers in this machine (i.e. how many bits do they hold)? Why?

2. Translate the number 42 into 8 bit signed binary notation. Show your work.

3. Translate the number 11.75 into 16 bit signed binary notation, assuming 6 bit for the decimal part. Show your work.

4. What is the largest number representable on 8 bits, signed?

5. Consider the following bit pattern: `1000000010000110`
1. If this is interpreted as a 16-bit unsigned integer, what integer would it represent? Show your work.
2. If the same bit pattern is interpreted as a 16-bit signed integer, what integer would it represent? Show your work.
3. If the same bit pattern is interpreted as a machine instruction, what instruction would it represent? Use the chart given in class (attached at the end).

6. Draw a circuit (using only AND, OR, and NOT gates) for the following truth table. You may, but you do not need to, use the sum-of-products approach discussed in class.

input 1input 2output 1
0 0 0
0 1 1
1 0 1
1 1 0

x
7. Draw a circuit (using only AND, OR, and NOT gates) for the following truth table. You may, but you do not need to, use the sum-of-products approach discussed in class. Be sure to indicate which line is output 1 and which line is output 2.

input 1 input 2 input 3 output 1 output 2
00001
00100
01000
01100
10010
10100
11010
11100

8. Design a truth table for the following expression.

`NOT(Found=No AND I<10,000) OR (I<=0)`

Let the logic variables P , Q and R represent the sub-expressions `Found=No` , ` I<10,000`, and `I<=0` respectively.

9. Design a logic circuit that implements a one-bit comparator for equality (1-bit CE): it takes as input 2 bits, and outputs 1 if the two bits are equal, and 0 otherwise. Show how to connect 1-bit CEs to get an 8-bit CE.

10. Let a and b be two Boolean variables. Draw the truth table for the following Boolean expressions:
a) `NOT (a AND b)`
b) `(NOT a) OR (NOT b)`

Are they equivalent? (Two expression are equivalent if their truth tables are identical).

x
11. What does the following assembly language program do? Let's denote by X, Y and Z the content of memory cells at adresses 16, 17, and 18 respectively. Show what changes occur in X, Y, and Z as its steps are executed, and then show the output. Use the instruction set discussed in class.

2STORE 17
3INCREMENT 18
4INCREMENT 18
6COMPARE 18
7JUMPLT 0
8OUT 17
9HALT
10
11
12
13
14
15
1612
170
181

x
12. Consider the following code:
```	a = r.readInt();
c = 0;
while (b>0) {
c = c+a;
b = b-1;
}
System.out.print(c);
```
1. Describe what the program does at a high level (e.e it gets two numbers a and b and output a+b).
2. Translate the program into machine instructions (using the attached instruction set). Please do not write your instructions in binary. Use English words for the operators and decimal numbers for the address in your instructions (e.g. LOAD 14, STORE 18). You may not assume that there is a particular value (e.g. zero) in a memory location where a variable is being stored until some instruction puts it there.

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

### What to turn in:

• The problems, hard copy.