Back to the 2024 paper

Module 1: Functional Block of computer and Data representaion

20242m

Explain the Addition and Subtraction Algorithm with the help of flowchart.

Worked SolutionAI Assisted

Addition / Subtraction Algorithm (Binary, 2's complement) – Flowchart

Uses registers: AA (accumulator), BB, QQ? For simple A±BA \pm B.

Algorithm:

  1. For addition: A←A+BA \leftarrow A + B using binary adder.
  2. For subtraction: A←A−B=A+(Bˉ+1)A \leftarrow A - B = A + (\bar{B}+1) (2's complement of B).
  3. Detect overflow: V=Cn⊕Cn−1V = C_{n} \oplus C_{n-1} (carry into sign xor carry out of sign).

Flowchart (Text)

           START
             |
             v
     +-----------------+
     | Load A = Augend |  
     |      B = Addend |
     +--------+--------+
              |
     +--------v--------+
     | Operation?      |---- SUB ----> B = ~B + 1 (2's comp)
     | ADD / SUB       |              (or SUB = ADD with Cin=1)
     +--------+--------+
              | ADD
              v
     +-----------------+
     | A = A + B       |
     | (parallel adder)|
     +--------+--------+
              |
     +--------v--------+
     | Overflow?       |--- Yes ---> Set V=1, Trap/Indicate
     | V = Cn xor Cn-1 |
     +--------+--------+
              | No
              v
     +-----------------+
     | Result in A,    |
     | Carry C, V flag |
     +--------+--------+
              |
             END

Detailed Step for Subtraction via Adder

SUB:  B' = NOT B
      Cin = 1
      Sum = A + B' + Cin
Equivalent to A + (2's complement of B)

4-bit Example

A=0101(+5)A=0101 (+5), B=0011(+3)B=0011 (+3)

  • ADD: 0101+0011=10000101+0011=1000 (8, overflow if signed 4-bit? V=1V=1 because positive+positive=negative)
  • SUB: A−B=0101+1101=0010A-B =0101 +1101 =0010 (+2) (11011101 is -3)

Hardware: Uses nn-bit parallel adder (ripple/CLA) with XOR gates on BB controlled by SUBSUB signal: Bi⊕SUBB_i \oplus SUB, Cin=SUBCin=SUB.

Overflow logic: If An−1,Bn−1A_{n-1}, B_{n-1} same and Sumn−1Sum_{n-1} different → overflow.

For magnitude (sign-magnitude) algorithm, extra step compares signs and magnitudes, but 2's complement above is standard in ALU.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.