Computer Organisation Lab File BCS352
Computer Organisation Lab File BCS352
SESSION: 2024-25
Name:-Anurag Sharma
Roll. No.:- 2300430130009
Subject:- Web Designing Lab
Subject Code:- BCS 353
Roll.No.:-2300430130009
Anurag Sharma
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-01
OBJECTIVE:-
THEORY:-
In data processing, addition of operands is one of the most basic operations performed by
different electronic devices like computers, calculators, etc. The electronic circuit that is
designed to perform the addition of two or more numbers, more specifically binary numbers,
is known as adder. As we know, the logic circuits use binary number system to perform the
operations, hence the adder is also referred to as a binary adder.
Depending on the number of binary digits that the adder circuit can add, adders (or binary
adders) are of two types:
Half Adder
Full Adder
In this article, we will discuss the implementation of full adder using half adder. But before
that let’s have a look into the basics of half adder and full adder.
In the half adder, the output of the XOR gate is the sum of two bits and the output of the
AND gate is the carry bit. However, in the half-adder circuit, the carry obtained in one
addition will not be forwarded in the next addition.
3
Roll.No.:-2300430130009
Anurag Sharma
In other words, a combinational circuit which is designed to add three binary digits and
produces two outputs (sum and carry) is known as a full adder. Thus, a full adder circuit adds
three binary digits, where two are the inputs and one is the carry forwarded from the previous
addition. The block diagram and circuit diagram of the full adder are shown in Figure-2.
It is clear that the logic circuit of a full adder consists of one XOR gate, three AND gates and
one OR gate, which are connected together as shown in Figure-2. Here, A and B are the input
bits, Cin is the carry from previous addition, S is the sum bit, and Cout is the output carry bit.
The output equations of the full adder are,
Now, let us discuss the realization of the full adder using half adders
Implementation of Full Adder using Half Adder
The logic diagram of the full adder using two half adders is shown in Figure-3:
4
Roll.No.:-2300430130009
Anurag Sharma
The block diagram of a full adder using two half adders is shown in Figure-4.
From the logic diagram of the full adder using half adders, it is clear that we require two
XOR gates, two AND gates and one OR gate for the implementation of a full adder circuit
using half-adders.However, the implementation of full adder using half adder has a major
disadvantage that is the increased propagation delay. That means, the input bits must
propagate through several gates in succession that increases the total propagation delay of the
full adder circuit.
Code
#include <stdio.h>
// Function to compute the sum and carry for a Half Adder void halfAdder(int A, int B, int *sum, int
*carry) {
*sum = A ^ B; // XOR operation for sum
*carry = A & B; // AND operation for carry
}
// Function to compute the sum and carry for a Full Adder void fullAdder(int A, int B,
int Cin, int *sum, int *carry) {
printf("--|---|-----|-------------------\n");
return 0;
}
6
Roll.No.:-2300430130009
Anurag Sharma
OUTPUT
7
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT-02
OBJECTIVE:
Implementing Binary -to -Gray, Gray -to -Binary code conversions.
THEORY:-
WHAT IS GRAY CODE?
Gray code is a sequence of binary numbers known as reflected binary code (RBC). Gray code
was introduced by Frank Gray. In gray code, two successive values differ by only 1 bit.
Conversion of binary codes to gray codes results in reducing the switching operations.
Gray Codes are unweighted codes, unlike binary codes. There are multiple names of gray
codes following:
Unit Distance Code
Minimum Error Code
Reflected Binary Code (RBC)
Cyclic Code
In the table below, 0 to 15 decimal numbers and their binary and gray codes are present.
Obviously, the table is not meant to be learned but to have a basic understanding.
Add the MSB to the next bit of the binary code, record the sum, and neglect the carry.
In the 2nd step, the XOR operation can also be done instead of adding MSB to the next bit
and neglecting the carry.
8
Roll.No.:-2300430130009
Anurag Sharma
Repeat step 2 again till the end of the binary code. Here’s the XOR truth table below to check
the results:
Here’s an example to understand the conversion:
9
Roll.No.:-2300430130009
Anurag Sharma
CODE
BINARY TO GRAY:-
#include <stdio.h>
int main() {
unsigned int binary;
return 0;
}
OUTPUT
10
Roll.No.:-2300430130009
Anurag Sharma
GRAY TO BINARY:-
#include <stdio.h>
int main() {
unsigned int grayCode, binaryCode;
%u\n", binaryCode);
return 0;
}
OUTPUT
11
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:03
OBJECTIVE
Implementing 3-8 line DECODER.
THEORY:-
A 3-to-8 line decoder is a combinational digital circuit that takes a 3-bit binary input and
produces 8 output lines. Each output line corresponds to a specific binary combination of the
input. Only one of the output lines is active (high) at a time, based on the input value. This
type of decoder is often used in digital circuits to enable specific functions or devices based
on the input.
3) Active Output: The output corresponding to the binary value of the input is active
(high), while all other outputs remain inactive (low). This is achieved by setting up AND
12
Roll.No.:-2300430130009
Anurag Sharma
gates for each output line, with one input of each AND gate connected to a specific bit of the
input and the other input connected to the inverted form of that bit.
Input: 000
Output 0: Active (High)
Gate 1: Input A is connected to bit 0 (the least significant bit) of the input.
Gate 2: Input B is connected to bit 1 of the input.
Gate 3: Input C is connected to bit 2 (the most significant bit) of the input.
The other AND gates for the remaining outputs are constructed similarly, each with different
input connections based on the binary value they represent.
In practice, 3-to-8 decoders are used as components in larger digital circuits to control
various operations and devices. They are crucial for demultiplexing, address decoding in
memory systems, and various other applications where input selection is needed based on
binary input values.
13
Roll.No.:-2300430130009
Anurag Sharma
CODE
#include <stdio.h>
14
Roll.No.:-2300430130009
Anurag Sharma
int main() {
unsigned int input;
printf("Enter a 3-bit binary input (e.g., 000 to 111): "); scanf("%u", &input);
return 0;
OUTPUT
15
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-04
OBJECTIVE:-
Implementing 4x1 and 8x1 MULTIPLEXERS.
THEORY:-
A multiplexer (MUX) is a digital logic device that allows you to select one input from multiple
inputs and route it to the output. A 4x1 MUX selects one input from four possible inputs, and an 8x1
MUX selects one input from eight possible inputs. Let's explain the implementation of both a 4x1
MUX and an 8x1 MUX in more detail:
In a 4x1 MUX, there are four input lines and one output line. The MUX is controlled by a select
signal that determines which input is connected to the output. Here's how it's implemented:
16
Roll.No.:-2300430130009
Anurag Sharma
1. Inputs: The 4x1 MUX has four input lines (input0, input1, input2, and input3).
2. Select Signal: The select signal (select) determines which input will be routed to the output. It
can take on values 0, 1, 2, or 3, corresponding to the four input lines.
3. MUX Function (mux4x1): The function `mux4x1` takes the four input values and the select
signal as arguments. It uses a conditional statement to select the appropriate input based on the select
signal.
In an 8x1 MUX, there are eight input lines and one output line. The MUX is controlled by a select
signal that determines which input is connected to the output. Here's how it's implemented:
1. Inputs: The 8x1 MUX has eight input lines (input0 to input7).
2. Select Signal: The select signal (select) determines which input will be routed to the output. It
can take on values from 0 to 7, corresponding to the eight input lines.
3. MUX Function (mux8x1): The function `mux8x1` takes an array of eight input values and the
select signal as arguments. It uses the select signal as an index to access the appropriate input from
the array.
17
Roll.No.:-2300430130009
Anurag Sharma
4. Output: The selected input from the array is returned as the output of the MUX
In both cases, the MUX selects one of the inputs based on the select signal. This functionality is used
in digital circuits for various purposes, such as data routing, address decoding in memory devices,
and signal selection. The select signal determines which input data gets passed through to the output,
and this can be a fundamental building block in digital systems for making decisions and routing
data efficiently.
CODE
#include <stdio.h>
int main() {
int input0, input1, input2, input3, select, result;
18
Roll.No.:-2300430130009
Anurag Sharma
return 0;
}
OUTPUT
#include <stdio.h>
int main() {
int inputs[8];
int select, result;
19
Roll.No.:-2300430130009
Anurag Sharma
if (result != -1)
printf("Output: %d\n", result); else
printf("Invalid select value. Please enter a value from 0 to 7.\n");
return 0;
}
OUTPUT
20
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-05
OBJECTIVE:-
21
Roll.No.:-2300430130009
Anurag Sharma
These excitation tables describe the behavior of D, JK, and T flip-flops in terms of their
inputs and clock signals. The X in the tables represents "don't care" conditions, which means
the input values for the clock signal do not matter for determining the flip-flop's behavior in
these tables.
CODE
#include <stdio.h>
23
Roll.No.:-2300430130009
Anurag Sharma
// Test T Flip-Flop Q = 0;
p T = 0;
r
printf("Q=%d T=%d => Q+=%d\n",
i
currentQ, T, tFlipFlop(currentQ, T));
n
t T = 1;
f printf("Q=%d T=%d => Q+=%d\n",
( currentQ, T, tFlipFlop(currentQ, T));
"
\ return 0;
n
T }
F OUTPUT
l
i
p
-
F
l
o
p
E
x
c
i
t
a
t
i
o
n
T
a
b
l
e
:
\
n
"
)
;
c
u
r
r
e
n
t
25
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-06
OBJECTIVE:-
26
Roll.No.:-2300430130009
Anurag Sharma
Design of an 8-bit Input/ Output system with four 8-bit Internal Registers.
THEORY:-
Designing an 8-bit Input/Output system with four 8-bit internal registers can be a complex
task, and the specific requirements and components may vary depending on your application.
However, I can provide you with a simplified conceptual design for such a system.
COMPONENTS NEEDED:
1. Microcontroller or Processor Unit: This serves as the central processing unit and
manages the overall operation of the system.
3. Internal Registers: You need four 8-bit internal registers to store data temporarily. These
can be implemented using flip- flops or memory elements.
4. Data Bus: An 8-bit data bus is required to transfer data between the microcontroller,
internal registers, and I/O devices.
5. Address Bus: An address bus is needed to select the appropriate register when reading
or writing data.
6. Control Logic: This controls the data flow between the registers, I/O devices, and the
processor. It also manages the timing and synchronization of operations.
DESIGN OVERVIEW:
1. Registers:
You have four 8-bit internal registers, which can be labeled as Reg0, Reg1, Reg2, and
Reg3.
These registers store data temporarily for processing by the microcontroller.
27
Roll.No.:-2300430130009
Anurag Sharma
2. Data Bus:
The 8-bit data bus allows data transfer between the
microcontroller, internal registers, and I/O devices.
Each register is connected to the data bus.
3. Address Bus:
You need an address bus to select which internal register to access.
The address bus should have enough bits to address the four registers (e.g., 2 bits for 4
registers).
4. Control Logic:
The control logic is responsible for managing data transfer between registers and I/O
devices.
It handles read and write operations based on the address and control signals.
5. Input/Output Interfaces:
You can have various I/O devices (e.g., sensors, displays) connected to the
input/output interfaces.
The microcontroller communicates with these devices using appropriate protocols, such
as GPIO, UART, or SPI.
OPERATIONS:
Data can be loaded into or read from the internal registers using the address bus and
data bus.
The microcontroller controls the data flow and the operations of the system through the
control logic.
Input data from external devices can be read into the registers for processing.
Processed data can be written to the registers and then sent to output devices.
#include <stdio.h>
// Define four 8-bit internal registers unsigned char
registers[4] = {0, 0, 0, 0};
}
}
28
Roll.No.:-2300430130009
Anurag Sharma
int main() {
int registerNum = 2;
unsigned char dataToWrite = 0xAB;
return 0;
}
OUTPUT
29
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-07
OBJECTIVE:-
30
Roll.No.:-2300430130009
Anurag Sharma
THEORY:-
Designing an 8-bit Arithmetic Logic Unit (ALU) is a complex task, and the specific design
may vary based on your requirements and constraints. However, I can provide you with a
simplified conceptual design for an 8-bit ALU.
Components Needed:
1. 8-bit Inputs (A and B): The two 8-bit operands that the ALU will perform operations on.
2. Operation Selector (Control Inputs): These control inputs determine the operation to be
performed (addition, subtraction, bitwise AND, OR, etc.).
3. 8-bit Output (Result): The result of the operation.
4. Flags: ALU typically sets flags like zero, carry, and
overflow to provide additional information about the result.
Design Overview:
1. Addition and Subtraction:
a. The ALU should be able to perform both addition and subtraction.
b. Subtraction can be implemented by taking the two's complement of the B
operand and adding it to A.
2. Bitwise Operations:
The ALU can perform bitwise AND, OR, XOR, and other operations.
These operations operate on each pair of corresponding bits of A and B.
3. Overflow Detection:
For addition and subtraction, overflow can be detected by examining the carry-out of
the most significant bit.
4. Zero Flag:
The zero flag is set if the result is all zeros.
5. Carry Flag:
The carry flag is set if there's a carry-out from the most significant bit during
addition.
31
Roll.No.:-2300430130009
Anurag Sharma
CODE
#include <stdio.h>
case SUBTRACTION:
result = A - B;
*carry = (A < B);
*overflow = ((*carry) ^ (A >> 7)) && ((*carry) ^ (B
>> 7));
break;
default:
printf("Unsupported operation\n");
}
return result;
}
int main() {
32
Roll.No.:-2300430130009
Anurag Sharma
return 0;
}
OUTPUT
33
Roll.No.:-2300430130009
Anurag Sharma
EXPERIMENT:-08
OBJECTIVE:-
Design the data path of a computer from its register transfer language description.
THEORY:-
Designing a complete data path for a computer system based on a register transfer language
description is a complex task, and the specific design would depend on various factors,
including the computer architecture, the instruction set, and performance requirements.
Here, I'll provide a simplified conceptual overview of the data path components and their
interactions based on a hypothetical description.
34
Roll.No.:-2300430130009
Anurag Sharma
Data Bus:
Connects all the data path components and allows data to be transferred between
them.
Please note that a complete real-world computer's data path would be much more complex,
supporting various addressing modes, multiple instructions, pipelining, and other advanced
features. The design can vary significantly based on the specific computer architecture and
requirements.
35
Roll.No.:-2300430130009
Anurag Sharma
CODE
#include <stdio.h>
// Decode instruction
int opcode = IR >> 4; // Extract opcode from the higher 4 bits
int operand1 = IR & 0xF; // Extract operand1 from the lower 4 bits
36
Roll.No.:-2300430130009
Anurag Sharma
int operand2 = IR & 0xF; // Extract operand2 from the lower 4 bits
default:
printf("Unsupported opcode\n");
}
int main() {
// Initialize registers, memory, and program counter registers[0] = 0;
registers[1] = 5;
registers[2] = 10;
registers[3] = 0;
return 0;
}
OUTPUT
37
Roll.No.:-2300430130009
Anurag Sharma
38
Roll.No.:-2300430130009