CS274: Computer Architecture - Computer Arithmetic: Addition and Subtraction
Activity Goals
The goals of this activity are:
- To add binary numbers including carry
- To identify overflow
- To use two's complement to negate and subtract values
The Activity
Directions
Consider the activity models and answer the questions provided. First reflect on these questions on your own briefly, before discussing and comparing your thoughts with your group. Appoint one member of your group to discuss your findings with the class, and the rest of the group should help that member prepare their response. Answer each question individually from the activity, and compare with your group to prepare for our whole-class discussion. After class, think about the questions in the reflective prompt and respond to those individually in your notebook. Report out on areas of disagreement or items for which you and your group identified alternative approaches. Write down and report out questions you encountered along the way for group discussion.
Model 1: Addition in Binary
Carry |
0 |
0 |
1 |
0 |
0 |
|
A = 5 |
|
0 |
0 |
1 |
0 |
1 |
B = 6 |
|
0 |
0 |
1 |
1 |
0 |
Sum = 11 |
X |
0 |
1 |
0 |
1 |
1 |
Questions
- What is 0 + 0 in binary? How about 0 + 1, 1 + 0, and 1 + 1?
- What should happen if you encounter 1 + 1 in terms of the carry bit? What should be done with the carry bit?
- What is 1 + 1 + 1?
- With a partner, choose two arbitrary values and ask the other to add them together in binary. Check your partner's work.
Model 2: Two's Complement of Binary Numbers and Subtraction
A = 2 |
0 |
0 |
0 |
0 |
1 |
0 |
One's Complement of A |
1 |
1 |
1 |
1 |
0 |
1 |
B = Two's Complement of A |
1 |
1 |
1 |
1 |
1 |
0 |
One's Complement of B |
0 |
0 |
0 |
0 |
0 |
1 |
A = Two's Complement of B |
0 |
0 |
0 |
0 |
1 |
0 |
Questions
- The two's complement of a value is the inverse of the value's bits, plus one. Why not use the one's complement to negate a value? That is, what if we simply flipped the bits and did not add one to the result?
- What is the most significant bit of a negative number using this system? A positive number?
- Why not simply set the most significant bit to 1 for negative numbers, and not bother flipping the bits?
- Subtract
6 - 4
by converting 4 to its two's complement value, and then adding them together.
Model 3: Overflow
Carry |
0 |
1 |
1 |
0 |
0 |
|
A = 5 |
|
0 |
0 |
1 |
0 |
1 |
B = 14 |
|
0 |
1 |
1 |
1 |
0 |
Sum = |
X |
1 |
0 |
0 |
1 |
1 |
Questions
- Given that the most significant bit of the sum is 1, this is a negative number. Using two's complement, determine this value's magnitude. Is it correct?
- Why is the result negative when we added two positive numbers together?
- In your own words, how can you tell that overflow occurred?
- How can you obtain overflow when subtracting two values? Provide an example.
- What is the largest 4 bit signed positive value that you can represent, and what is the smallest?
- What is the largest 32 bit signed positive value that you can represent, and what is the smallest?
Submission
I encourage you to submit your answers to the questions (and ask your own questions!) using the Class Activity Questions discussion board. You may also respond to questions or comments made by others, or ask follow-up questions there. Answer any reflective prompt questions in the Reflective Journal section of your OneNote Classroom personal section. You can find the link to the class notebook on the syllabus.