Introduction to Computer Science_HW2_solution
Introduction to Computer Science_HW2_solution
Homework_2
1 Show the result of the following operations. (ch.4)
a NOT (99)16 (66)16
b NOT (FF)16 (00)16
c NOT (00)16 (FF)16
d NOT (01)16 (FE)16
3 Using a 16-bit allocation, first convert each of the following numbers to two’s complement, do the
operation, and the convert the result to decimal. (ch.4)
a 161 + 1023 1184
b 161 – 1023 -862
c -161 + 1023 862
d -161 – 1023 -1184
4 Using an 8-bit allocation, first convert each of the following numbers to sign-and-magnitude
representation, do the operation, and the convert the result to decimal. (ch.4)
a 19 + 23 42
b 19 – 23 -4
c -19 + 23 4
d -19 – 23 -42
5 An imaginary computer has sixteen data register (R0 to R15), 1024 words in memory, and 16 different
instructions (add, subtract, and so on). What is the minimum size of an instruction in bits if a typical
instruction uses the following format: instruction M R2 (ch.5)
18 bits
6 In Question 5, if the computer uses the same size of word for data and instructions, what is the size of
each data register. (ch.5)
18 bits
7 A computer uses memory-mapped I/O addressing, the address bus uses 10 lines (10 bits). If memory
made up of 1,000 words, how many four-register controllers can be accessed by the computer.
(ch.5)
6
8 We need to flip the three rightmost and the two leftmost bits of a pattern. Show the mask and the
operations. (ch.4)
XOR 11000111
9 Using the instruction set of the simple computer in Section 5.7, write the code for a program that
perform the following calculation:
D ← A+B+C
A, B, C, and D are integers in two’s complement format. The user types the value of A, B, and C, and
the value of D is displayed on the monitor. (ch.5)
10 Using the instruction set of the simple computer in Section 5.7, write the code for a program that
perform the following calculation:
B ← A-2
A and 2 are integers in two’s complement format. The user types the value of A and the value of B is
displayed on the monitor. (Hint: use the decrement instruction.) (ch.5)(抱歉助教出題時打成 D)