Uploaded by Shivani Sarsar

midterm 1 202110.pdf

advertisement
Langara College
Department of Computer Science
CPSc 1050 Section W08 – Introduction to Computer Science
Feb 9th, 2021
Instructor: Haotian Pang
Midterm Examination 1
Name:
Student ID:
Section Number:
80 minutes – 100 marks
1.
2.
3.
4.
5.
6.
7.
8.
Write the answers in the space provided or in a separate answer sheet.
Show your steps for each questions.
This exam is open book. You may use a calculator.
You may use the internet to access course material on Brightspace.
You cannot directly search the questions on internet.
You cannot use the internet to communicate with others.
You can use a pen or pencil, or you can type on your computer.
Make sure your solution is in a single pdf file. Submit it to Brightspace (Assignment Midterm 1) submission folder.
Page 1 of 12
1. [4 marks] Perform the following Octal addition directly, without converting to another base.
6 6 3
+ 7 5 7
------------------
2. [4 marks] Perform the following Hexadecimal addition directly, without converting to
another base, where XYZ is the last three digits of your student number. For example, if
your student number is 100321487, then XYZ is 487 (in hexadecimal).
E A 3 B
+
X Y Z
---------------------------
3. [3 marks] What is the lowest base in which XYZ would be a valid number, where XYZ is the
last three digits of your student number.
4. [4 marks] Convert the decimal number XYZ to base 8, where XYZ is the last three digits of
your student number.
Page 2 of 12
5. [4 marks] Convert the octal number 246 to decimal.
6. [6 marks] Convert the binary number 10011.1012 to decimal. The binary number is given in
unsigned magnitude representation.
7. [4 marks] Convert the 2's complement binary number 1011 to decimal.
8. [8 marks] Simplify the Boolean Expression (AB + AB’)(A+C) + C +AC. Show all the steps.
Page 3 of 12
Character Huffman Code Character Huffman Code
A
00
O
10010
E
11
I
10011
T
010
N
101000
C
0110
F
101001
L
0111
H
101010
S
1000
D
101011
R
1011
9.
a) [6 marks] What word does the following bit sequence represent?
101001100111010010010001001001100110111011
b) [4 marks] How many bits would it take to represent the word from part a) using ASCII
characters assuming that one would use 8 bits per character?
c) [4 marks] What is the compression ratio between parts a) and b)?
10. [4 marks] Assume a language has 120 letters. How many bits would be required to represent
its alphabet?
Page 4 of 12
11.
a) [9 marks] Trace the execution of the following “Super Simple CPU” program and for
each step record the values of the Accumulator, Mem[10] (memory location 10), Mem[11],
and Mem[12] . The values before the execution starts are shown.
TOP
LOD
JZR
JNG
SUB
STO
JMP
LDI
STO
STP
LDI
STO
STP
XXX
YYY
11
XXX
YYY
10
11
TOP
1
12
0
12
Accumulator
Mem[10]
Mem[11]
Mem[12]
16
3
5
36
Page 5 of 12
b) [3 marks] What would have been the final result in Mem[12] if the Mem[11] initially had
the value 6?
c) [4 marks] What does this program do?
12. [10 marks] There are two numbers X and Y. X is stored in memory location 13, and Y is
stored in memory location 14. Write a Super Simple CPU assembler program to check if X is
less than Y. If the answer is yes, store 1 to memory location 15, otherwise store 0 to memory
location 15.
Page 6 of 12
13. Consider the following truth table for a circuit where A, B, C are the inputs and X is the sole
output.
A
0
0
0
1
0
1
1
1
B
0
0
1
0
1
0
1
1
C
0
1
0
0
1
1
0
1
X
0
0
0
1
0
1
1
0
a) [6 marks] Give a Boolean expression for the circuit and simplify it.
b) [3 marks] Draw a circuit implementing this expression using standard logic gate symbols.
Page 7 of 12
14. [10 marks] Show that these two circuits are equivalent by two methods. You may
assume that the inputs are A and B and the output is X for both circuits.
Page 8 of 12
Super Simple CPU Instructions Set
1111 STP This stops the computer; no more fetch/decode/execute cycles until you reset.
--------------------------------------------------------------------------------------------------------------------0001 ADD Fetch a number from memory and add it to the contents of the accumulator, replacing
the value in the accumulator. (E.g., 0001000000001111: Get the value at memory location 15
and add that to the accumulator.)
--------------------------------------------------------------------------------------------------------------------0010 SUB Fetch a number from memory and subtract it from the contents of the accumulator,
replacing the value in the accumulator.
--------------------------------------------------------------------------------------------------------------------0011 LOD Fetch a number from memory and store it in the accumulator, replacing the
accumlator’s old value. (E.g., 0011000000001111: Get the value at memory location 15 and
store that value in the accumulator.)
--------------------------------------------------------------------------------------------------------------------0100 LDI Load immediate; the value to be put in the accumulator is the operand (the rightmost
12 bits of the instruction); do not go to memory like LOD. (E.g., 0100000000001111: Store the
value 15 in the accumulator.)
--------------------------------------------------------------------------------------------------------------------0101 STO Store the accumulator’s value in memory at the indicated location.
(E.g., 0101000000001111: Store the accumulator’s value in memory location 15.)
--------------------------------------------------------------------------------------------------------------------0110 INP Ask the user for one number and store that in the accumulator.
--------------------------------------------------------------------------------------------------------------------0111 OUT Copy the value in the accumulator to the output area.
--------------------------------------------------------------------------------------------------------------------1000 JMP Jump to the instruction at the indicated memory address. (E.g.,1000000000001111:
Put the value 15 into the PC, which will cause the next instruction to be taken from location 15
of the memory.)
--------------------------------------------------------------------------------------------------------------------1001 JNG Jump to the instruction at the indicated memory location if the
accumulator’s value is negative; otherwise just add 1 to the PC. (E.g., 1001000000001111: Put
the value 15 into the PC, if
accumulator < 0; otherwise go to the next instruction.)
--------------------------------------------------------------------------------------------------------------------1010 JZR Jump to the instruction at the indicated memory location if the
accumulator’s value is zero; otherwise just add 1 to the PC. (E.g., 1010000000001111: Put the
value 15 into the PC, if accumulator = 0; otherwise go to the next instruction.) Each instruction
in this super-simple computer has two parts: opcode and operand
Page 9 of 12
Basic Gates
NOT Gate
AND Gate
OR Gate
XOR Gate
Page 10 of 12
Boolean Identities
Property
AND
OR
Commutative
AB = BA
A+B=B+A
Associative
(AB)C = A(BC)
(A + B) + C = A + (B + C)
Distributive
A(B + C) = (AB) + (AC)
A + (BC) = (A + B)(A + C)
Identity
A1 = A
A+0=A
Complement
A(A') = 0
A + (A') = 1
DeMorgan’s Law
(AB)' = A' + B'
(A + B)' = A'B'
Idempotent
AA = A
A+A=A
Boundedness
A0 = 0
A+1=1
Involution
(A')' = A
A' means NOT A
Page 11 of 12
Page 12 of 12
Download