0% found this document useful (0 votes)
32 views

Introduction to Computer Science_HW2_solution

Uploaded by

kh1252689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Introduction to Computer Science_HW2_solution

Uploaded by

kh1252689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Computer Science

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

2 Show the result of the following operations. (ch.4)


a (99)16 OR (99)16 (99)16
b (99)16 OR (00)16 (99)16
c (99)16 OR (FF)16 (FF)16
d (FF)16 OR (FF)16 (FF)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)

Step Code(hexadecimal) Description


1 1FFE // RF ← MFE, Input A from keyboard to RF
2 240F // M40 ← RF, Store A in M40
3 1FFE // RF ← MFE, Input B from keyboard to RF
4 241F // M41 ← RF, Store B in M41
5 1FFE // RF ← MFE, Input C from keyboard to RF
6 242F // M42 ← RF, Store C in M42
7 1040 // M40 ← R0, Load A from M40 to R0
8 1141 // M41 ← R1, Load B from M41 to R1
9 1242 // M42 ← R2, Load C from M42 to R2
10 3310 // R3 ← R1 +R0, Add A to B and store in R3
11 3432 // R4 ← R3 +R2, Add C to (A + B) and store in R4
12 2434 // M43 ← R4, Store The result in M43
13 1F43 // RF ← M43, Load the result to RF
14 2FFF // MFF ← RF, Send the result to the monitor
15 0000 // Halt

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)

Step Code(hexadecimal) Description


1 1FFE // RF ← MFE, Input A from keyboard to RF
2 240F // M40 ← RF, Store A in M40
3 1040 // M40 ← R0, Load A from M40 to R0
4 B000 // R0 ← R0 − 1, Decrement A
5 B000 // R0 ← R0 − 1, Decrement A
6 2410 // M41 ← R0, Store The result in M41
7 1F41 // RF ← M41, Load the result to RF
8 2FFF // MFF ← RF, Send the result to the monitor
9 0000 // Halt

You might also like