---
# System prepended metadata

title: Digital Design Lab 4 - Arithmetic Operations
tags: [IUG, Computer Engineering, Digital Design, Digital]

---

---
description: In this lab, we are going to design logic circuits that could perform arithmetic operations such as addition, subtraction, and multiplication, we will achieve most of these operations using addition only.
---
<h1 style='border: none'><center>Digital Design Lab 4</center></h1>
<h2 style='border: none'><center>Arithmetic Operations</center></h2>
<h5><center>The Islamic University of Gaza<br>Engineering Faculty<br>Department of Computer Engineering</center></h5>
<h6>Author: Mohammed Nafiz ALMadhoun<span style="float:right">2021/10/25</span></h6>

---
## Introduction

In this lab, we are going to design logic circuits that could perform arithmetic operations such as addition, subtraction, and multiplication, we will achieve most of these operations using addition only.

## Addition

### Full-Adder

As you remember in the previous lab, we've already designed the half-adder, which can add two bits together, the idea here is to create a design that could add three bits together.

The choice of 3 bits is not an arbitrary choice, at most in one addition we will add 3 bits which are first input, a second input, and the carry from the previous addition.
<center>


$\begin{matrix}
carry & \scriptstyle \color{Gray}{1} & \scriptstyle \color{Gray}{1} & \scriptstyle \color{Gray}{1} & \scriptstyle \color{Gray}{0}\\
 & 0 & 1 & 0 & 1 \\ 
{+} & 0 & 0 & 1 & 1 \\ 
\hline
& 1 & 0 & 0 & 0
\end{matrix}$

</center>

This design will allow us to easily create bigger adders as we will see in the next section.

<style>
.markdown-body table {
    margin: 0 auto 16px;
    width: fit-content;
}
</style>


|  Cin  |  A  | B |  Cout  | S |
|:---:|:---:|:---:|:---:|:----:|
|  0  |  0  |  0  |     |      |
|  0  |  0  |  1  |     |      |
|  0  |  1  |  0  |     |      |
|  0  |  1  |  1  |     |      |
|  1  |  0  |  0  |     |      |
|  1  |  0  |  1  |     |      |
|  1  |  1  |  0  |     |      |
|  1  |  1  |  1  |     |      |

As usual, we can design our full-adder using the truth table, or we could think about it as a regular summation.

Note that if you want to add three numbers together, you will add the first two numbers, then you will add the third to the summation of the previous two, use this idea to design a full-adder using two **half-adders**.

### 4-Bits Adder

Using the previous **full-adder** design, we can add as many bits as we want, by simply connecting half-adders together.

<center>

![4-Bit Adder](https://i.imgur.com/lvjNcE7.png =450x)
4-Bit Adder
</center>

**Note:** We could use buses in Logisim, a bus is just several wires.

<div style="page-break-after: always;"></div>

## Subtraction

### Subtractor from Adder

As you know from your course lectures, if a negative number is represented as 2nd complement, we could add it to another number and that will give us the correct result represented also in 2nd complement.

We could use this idea to create a subtractor from an adder, first, we should get the  2nd complement of the second input, then we just add the numbers together.

To get the 2nd complement, we could easily just invert the bits of it and add one to it (we can add the one to it using the first carry input).

<center>

![4-Bit Subtractor](https://i.imgur.com/Z6cuS6D.png =450x)
4-Bit Subtractor
</center>

<div style="page-break-after: always;"></div>

### Adder-Subtractor Design

We can build an inverter using `XOR` if we fixed one input to `1`, and it will work as a buffer if we fixed that input to `0`, using this idea we can build a design that acts as Adder or Subtractor using a selection signal (0 to add, 1 to subtract).

Note that in addition, the first carry should be `0`, and in subtraction, it should be `1`, thus we could connect the previous signal directly to the first carry input.

<center>


![4-Bit Adder-Subtractor](https://i.imgur.com/ckMhZoG.png =500x)
4-Bit Adder-Subtractor
</center>


## Multiplication 

Please return to your textbook section **4.7** :)

<div style="page-break-after: always;"></div>

## Lab Tasks

### Task 1: Build Full-Adder using two Half-Adders. (6 Marks)

In this task, you should create a full-adder using two half-adders.
**Simulate your design using Logisim before connecting a single wire**

You should use: 
74/08 (Quad 2-Input AND): https://www.futurlec.com/Datasheet/74ls/74LS08.pdf
74/32 (Quad 2-Input OR) : https://www.futurlec.com/Datasheet/74ls/74LS32.pdf
74/86 (Quad 2-Input XOR): https://www.futurlec.com/Datasheet/74ls/74LS86.pdf

### Task 2: Build 2-Bits Adder. (4 Marks)
In this task, you should connect two half-adders to create a 2-bits adder, then connect the output of the adders to the 7-segments display in the KL-31001.
**Note:** You should not use any extra ICs.


<span style="color:#e20000" >**DON'T POWER UP THE KL-31001 WITHOUT MY PERMSIONS.**</span>

<center>Good luck in your midterm exams ❤</center>

###### tags: `Digital Design` `Digital` `IUG` `Computer Engineering`
<center>End Of Lab 4</center>