4 Arithmetic And Logical Operations

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.

Arithmetic and Logical Operations: notes

Arithmetic micro-operations

The basic arithmetic microoperations are addition, subtraction, increment, decrement and negation (taking the complement).

MicrooperationMeaning
$R3 \leftarrow R1 + R2$Add the contents of R1 and R2, put the sum in R3
$R3 \leftarrow R1 + \overline{R2} + 1$Subtract: R1 minus R2 using 2's complement
$R2 \leftarrow \overline{R2}$Complement (invert all bits) of R2
$R2 \leftarrow \overline{R2} + 1$Negate R2 (2's complement)
$R1 \leftarrow R1 + 1$Increment
$R1 \leftarrow R1 - 1$Decrement

Subtraction is done by adding the 2's complement of the second number. This lets one adder do both jobs. A binary adder-subtractor uses a mode input M: when $M = 0$ the circuit adds, and when $M = 1$ it subtracts. Each bit of B goes through an XOR gate with M, and M is also the first carry input.

Logical micro-operations

Logical microoperations work on each bit of a register separately, as if each bit were a separate variable.

OperationSymbolResult for each bit
AND$A \wedge B$1 only if both bits are 1
OR$A \vee B$1 if at least one bit is 1
XOR$A \oplus B$1 if the bits differ
Complement$\overline{A}$Each bit inverted

Two variables can form 16 different logic functions. AND, OR, XOR and complement are the ones used most.

Example with $A = 1010$ and $B = 1100$:

$$\begin{aligned} A \wedge B &= 1000 \ A \vee B &= 1110 \ A \oplus B &= 0110 \ \overline{A} &= 0101 \end{aligned}$$

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]

Arithmetic micro-operations are basic operations performed on numeric data stored in registers. They involve arithmetic computations on binary data. --- The most fundamental arithmetic micro-operation. The contents of two registers are added and the result is stored in a destination register. Not...

Open this answer on its own page →

2081 · 5 marks

Explain different arithmetic and binary micro-operations in brief. [5]

Arithmetic micro-operations perform basic arithmetic operations on numeric data stored in registers. Operation Symbolic Notation Description ------------------------------------------- Add R3 ← R1 + R2 Contents of R1 and R2 are added Subtract R3 ← R1 - R2 R2 is subtracted from R1 Increment R1 ← R...

Open this answer on its own page →

2078 · 5 marks

Explain arithmetic micro-operations with suitable examples [5]

Arithmetic micro-operations are the basic operations performed on numeric data stored in registers. These operations include addition, subtraction, increment, decrement, and shift operations that alter the numeric value of data in registers. --- The general notation used is: R3 ← R1 + R2 means "a...

Open this answer on its own page →

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 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

MethodComplement of 1197SumCarry out?Handling of the carryResult
9's complement880210036YesAdded back to the least significant digit$+37$
10's complement880310037YesDiscarded$+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$.

Open this answer on its own page →

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 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

AB (Mask)A OR B (Result)
000 (unchanged)
101 (unchanged)
011 (set to 1)
111 (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

FeatureDetail
OperationA OR B
Gate UsedOR Gate (one per bit)
Effect of B=1Sets corresponding bit to 1
Effect of B=0Leaves corresponding bit as-is
ApplicationSetting specific bits in a register without disturbing others
Open this answer on its own page →

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]

In signed magnitude representation, a number has: - Sign bit (MSB): 0 for positive, 1 for negative - Magnitude bits: remaining bits representing the absolute value --- The hardware consists of the following components: Component Function --------------------- Register A Holds first operand (sign ...

Open this answer on its own page →

Logical micro-operations

2080.1 · 5 marks

Explain different logical micro-operations with example. [5]

Logical micro-operations perform bit-wise operations on the binary data stored in registers. Unlike arithmetic operations, they treat each bit independently (no carry propagation between bits). --- Let registers A = 1010 and B = 1100 (4-bit examples) --- - Performs bit-wise AND between two regist...

Open this answer on its own page →