Microprocessor and Computer Architecture · Unit 4
Arithmetic and Logical Operations
Exam-focused notes for Arithmetic and Logical Operations (Microprocessor and Computer Architecture, BIT151): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Arithmetic and Logical Operations in short
Computers do all their work with binary numbers and bit-level operations. This chapter shows how addition, subtraction and logic are done on registers, and how negative numbers are stored. These methods are the base of every ALU design.
What this unit covers
- Arithmetic micro-operations
- Logical micro-operations
- Selective set logical operations
- Binary addition and subtraction of signed magnitude data
- Ones complement and twos complement representation
- Nines complement and tens complement methods
Arithmetic micro-operations
2082 · 5 marks
Explain different arithmetic micro operations in brief. [5]
2081 · 5 marks
Explain different arithmetic and binary micro-operations in brief. [5]
2078 · 5 marks
Explain arithmetic micro-operations with suitable examples [5]
Nines complement and tens complement methods
2082 · 5 marks
Subtract $(1197){10}$ from $(1234){10}$ using the 999's complement and 10's complement methods. [5]
Show solved answerHide answer
Subtraction Using 9's and 10's Complement Methods
"Subtract $(1197){10}$ from $(1234){10}$" means the minuend is 1234 and the subtrahend is 1197, so the value wanted is $1234 - 1197$. Both numbers have four digits, so every complement below is taken to four digits.
9's complement method
The 9's complement of the subtrahend is found by subtracting each digit from 9:
$$9999 - 1197 = 8802$$
Adding this to the minuend replaces the subtraction:
$$1234 + 8802 = 10036$$
1 2 3 4
+ 8 8 0 2
---------
1 0 0 3 6 (carry out of the most significant digit)
A carry out of the most significant digit tells us the result is positive. In the 9's complement method that carry is not simply discarded: it is added back into the least significant digit, which is why the rule is called the end around carry.
$$0036 + 1 = 0037$$
Therefore $1234 - 1197 = +37$.
10's complement method
The 10's complement is one more than the 9's complement:
$$8802 + 1 = 8803$$
$$1234 + 8803 = 10037$$
1 2 3 4
+ 8 8 0 3
---------
1 0 0 3 7 (carry out of the most significant digit)
Here the carry is simply discarded rather than added back, because the extra 1 has already been built into the complement. What remains is the answer directly.
Therefore $1234 - 1197 = +37$, agreeing with the 9's complement method and with ordinary decimal subtraction.
Summary
| Method | Complement of 1197 | Sum | Carry out? | Handling of the carry | Result |
|---|---|---|---|---|---|
| 9's complement | 8802 | 10036 | Yes | Added back to the least significant digit | $+37$ |
| 10's complement | 8803 | 10037 | Yes | Discarded | $+37$ |
Had the operands been the other way round, $1197 - 1234$, no carry would have been produced, and the rule for that case is to recomplement the sum and attach a minus sign, which gives $-37$.
Selective set logical operations
2080 · 5 marks
What is selective set logical operation? Draw the hardware circuit of selective set logical operation. [5]
Show solved answerHide answer
Selective Set Logical Operation
Definition
Selective Set is a logical operation that uses the OR operation to selectively set (force to 1) specific bits of a register (operand A) based on a mask operand (operand B), while leaving the remaining bits unchanged.
- If a bit in the mask (B) = 1, the corresponding bit in the result is set to 1 (regardless of A).
- If a bit in the mask (B) = 0, the corresponding bit in the result remains unchanged (retains the value of A).
The operation is defined as:
$$A \leftarrow A \text{ OR } B$$
Key Principle
| A | B (Mask) | A OR B (Result) |
|---|---|---|
| 0 | 0 | 0 (unchanged) |
| 1 | 0 | 1 (unchanged) |
| 0 | 1 | 1 (set to 1) |
| 1 | 1 | 1 (set to 1) |
- Wherever B = 1, the bit is forced/set to 1.
- Wherever B = 0, the bit is left as it is.
Example
Let A = 1010 0110 and B (mask) = 0000 1111
A = 1010 0110
B = 0000 1111
---------
A OR B= 1010 1111
The lower 4 bits are all set to 1 by the mask.
Hardware Circuit of Selective Set Operation
The circuit uses OR gates for each bit position. Each OR gate takes one bit from register A and the corresponding bit from mask B as inputs.
Bit position: n-1 ... 1 0
| | |
A[n-1] --+--\ A[1] -+--\ A[0] -+--\
| OR --> R[n-1] | OR->R[1] | OR --> R[0]
B[n-1] --+--/ B[1] -+--/ B[0] -+--/
Detailed Single-Bit Circuit (for one bit position):
A[i] ----\
[OR Gate] -----> Result R[i]
B[i] ----/
Full n-bit Circuit Diagram:
A[n-1] ---| A[1] ---| A[0] ---|
| OR|-->R[n-1] | OR|-->R[1] | OR|-->R[0]
B[n-1] ---| B[1] ---| B[0] ---|
(Each bit position has one OR gate)
+-------+ +-------+ +-------+ +-------+
| A[n-1]| | A[2] | | A[1] | | A[0] |
+---+---+ +---+---+ +---+---+ +---+---+
| | | |
[OR] [OR] [OR] [OR]
| | | |
+---+---+ +---+---+ +---+---+ +---+---+
| B[n-1]| | B[2] | | B[1] | | B[0] |
+-------+ +-------+ +-------+ +-------+
| | | |
R[n-1] R[2] R[1] R[0]
Summary
| Feature | Detail |
|---|---|
| Operation | A OR B |
| Gate Used | OR Gate (one per bit) |
| Effect of B=1 | Sets corresponding bit to 1 |
| Effect of B=0 | Leaves corresponding bit as-is |
| Application | Setting specific bits in a register without disturbing others |
Binary addition and subtraction of signed magnitude data
2078 · 5 marks
Explain hardware implementation and algorithm for subtraction and addition of signed magnitude data with suitable diagram. [5]
Logical micro-operations
2080.1 · 5 marks
Explain different logical micro-operations with example. [5]
Make Unit 4 stick
Practice BIT151 with flashcards & quizzes