Professional Documents
Culture Documents
Technology
1
Index
S Name of Assignment Page Assigned Submission
No. No. Date Date
2
• Design 4 bit carry look ahead adder
3
Assignment 1
XRA A
MOV C,A
LOOP: ADD B
JNC SKIP
INR C
SKIP: DCR B
JNZ LOOP
LXI H,0000H
MOV M,C
INX H
MOV M,A
HLT
Output:
4
Q2) Find the sum of 5+6+7 using 1+2+..7 - 1+2+3+4 using loop.
MVI B,4H
LOOPB: ADD B
DCR B
JNZ LOOPB
OUT 05H
MVI B,7H
LOOPD: ADD B
DCR B
JNZ LOOPD
OUT 06H
IN 05H
MOV B,A
IN 06H
SUB B
OUT 07
HLT
Output:
5
Assignment 2
OUTPUT:
6
Q2) Find the square of a 8-bit number.
CODE: XRA A
MOV C,A
LXI H,0000H
MOV B,M
MOV D,M
LOOP: ADD B
JNC SKIP
INR C
SKIP: DCR D
JNZ LOOP
INX H
MOV M,A
INX H
MOV M,C
HLT
OUTPUT:
7
Q3) Subtract two 8-bit numbers stored at memory location 0020H and 0021H
and store the result and borrow at locations 0022H and 0023H respectively.
CODE: XRA A
MOV C,A
LXI H,0020H
MOV A,M
INX H
SUB
JNC SKIP
INR C
SKIP: INX H
MOV M,A
INX H
MOV M,C
HLT
OUTPUT:
8
Assignment 3
Q) Write a program to find the factorial of a numbers. Fetch the number from
memory location 0100H. Store the result in memory locations 0101H and
0102H (Result may be a 16-bit number).
CODE:
LXI H,0100H
MOV E,M
MVI D,00H
MOV B,M
DCR B
OUTPUT:
9
Assignment 4
EXPERIMENT 1
AIM: To simulate SISO shift registers using D-Flip Flops for the serial input bit
string “1010”.
DESCRIPTION: Shift registers hold the data in their memory which is moved
or “shifted” to their required positions on each clock pulse. The data in SISO
register is shifted serially “IN” and “OUT” of the register, one bit at a time in
either a left or right direction under clock control.
CIRCUIT:
10
11
EXPERIMENT 2
AIM: To simulate SISO shift registers by realising D-Flip Flops using JK Flip
Flops for the serial input bit string “1010”.
DESCRIPTION: Shift registers hold the data in their memory which is moved
or “shifted” to their required positions on each clock pulse. The data in SISO
register is shifted serially “IN” and “OUT” of the register, one bit at a time in
either a left or right direction under clock control.
CIRCUIT:
12
13
EXPERIMENT 3
AIM: To simulate SIPO shift registers using D-Flip Flops for the serial input bit
string “1010”.
DESCRIPTION: Shift registers hold the data in their memory which is moved
or “shifted” to their required positions on each clock pulse. The register is
loaded with serial data, one bit at a time, with the stored data being available at
the output in parallel form.
CIRCUIT:
14
15
EXPERIMENT 4
AIM: To simulate SIPO shift registers by realising D-Flip Flops using JK Flip
Flops for the serial input bit string “1010”.
DESCRIPTION: Shift registers hold the data in their memory which is moved
or “shifted” to their required positions on each clock pulse. The register is
loaded with serial data, one bit at a time, with the stored data being available at
the output in parallel form.
CIRCUIT:
16
Assignment 5
Experiment 1
AIM: To simulate PISO shift registers using D-Flip Flops for the serial input bit string
“1010”.
OBJECTIVE: To study the behaviour of different modes of data input by using PISO shift
register.
DESCRIPTION: Parallel-in/ serial-out shift registers do everything that the previous serial-
in/ serial-out shift registers do plus input data to all stages simultaneously. The parallel-in/
serial-out shift register stores data, shifts it on a clock-by-clock basis, and delays it by the
number of stages times the clock period.
CIRCUIT:
17
18
Experiment 2
AIM: To simulate PISO shift registers by realising D-Flip Flops using JK Flip Flops for the
serial input bit string “1010”.
OBJECTIVE: To study the behaviour of different modes of data input by using PISO shift
register.
DESCRIPTION: Parallel-in/ serial-out shift registers do everything that the previous serial-
in/ serial-out shift registers do plus input data to all stages simultaneously. The parallel-in/
serial-out shift register stores data, shifts it on a clock-by-clock basis, and delays it by the
number of stages times the clock period.
CIRCUIT:
19
20
Experiment 3
AIM: To simulate PIPO shift registers using D-Flip Flops for the serial input bit string
“1010”.
OBJECTIVE: To study the behaviour of different modes of data input by using PIPO shift
register.
DESCRIPTION: Parallel-in/ serial-out shift registers do everything that the previous serial-
in/ serial-out shift registers do plus input data to all stages simultaneously.
CIRCUIT:
21
Experiment 4
AIM: To simulate PIPO shift registers by realising D-Flip Flops using JK Flip Flops for the
serial input bit string “1010”.
OBJECTIVE: To study the behaviour of different modes of data input by using PIPO shift
register.
DESCRIPTION: Parallel-in/ serial-out shift registers do everything that the previous serial-
in/ serial-out shift registers do plus input data to all stages simultaneously.
22
CIRCUIT:
Assignment 6
Experiment 1
Objective : To design the 4-bit ripple carry adder using full adders and to check it’s activity after
implementation.
Description : A full adder is a combinational circuit that forms the arithmetic sum of three bits, consists
of 3 inputs (A, B & Cin) and 2 outputs (Sum & Cout). Where, Sum = A Ꚛ B Ꚛ Cin and Cout = Cin(A Ꚛ
B) + AB
23
Now, in a ripple carry adder which is designed by full adders :
● Each full adder has to wait for it’s Cin from it’s previous stage full adder.
● Thus, nth full adder has to wait until all (n-1) full adders have completed their operations.
● This causes a delay and makes ripple carry adder extremely slow.
● The situation becomes worst when the value of n becomes very large.
● To overcome this advantage, carry look ahead adder comes into play.
Simulated circuit :
24
25
26
27
Experiment 2
Aim : To simulate 16-bit Ripple carry adder using 4-bit Ripple carry adders.
Objective : To design the 16-bit ripple carry adder using full adders and to check it’s activity after
implementation.
Description : Now, in a 16-bit ripple carry adder which is designed by using 4-bit ripple carry adders :
● Each RC adder has to wait for it’s Cin from it’s previous stage RC adder.
● Thus, nth RC adder has to wait until all (n-1) RC adders have completed their operations.
Simulated circuit :
28
29
30
Assignment 7
Description: A carry look-ahead adder reduces the propagation delay by introducing more complex
hardware. In this design, the ripple carry design is suitably transformed such that the carry logic over
fixed groups of bits of the adder is reduced to two-level logic.
In ripple carry adders, for each adder block, the two bits that are to be added are available instantly.
However, each adder block waits for the carry to arrive from its previous block. So, it is not possible to
generate the sum and carry of any block until the input carry is known. The (𝑖)𝑡ℎ block waits for the( 𝑖 −
1)𝑡ℎ block to produce its carry. So there will be a considerable time delay which is carry propagation
delay.
● Carry generate = Gi
● Carry propagate = Pi
Pi = Ai Ꚛ Bi
Gi = Ai.Bi
Si = Pi Ꚛ Ci
Ci+1 = Gi + Pi.Ci
And
31
4 – bit CLA Circuit:
32
33
Q2) Design 6 – bit carry look ahead adder.
34
6 – bit CLA Circuit:
35
36
37
Assignment 8
Solution.
#include <bits/stdc++.h>
int ans = 0;
return ans;
random_device dev;
38
mt19937 rng(dev());
return dist(rng);
class MainMemoryAddress
public:
vector<bool> address;
MainMemoryAddress()
void create(int r)
int i = address_size - 1;
while (r)
i = i - 1;
r = r >> 1;
39
return {line, no_in_line};
void generateNextReference()
if (no_in_line == 3)
line++;
no_in_line = 0;
else
no_in_line++;
create((line * 4) + no_in_line);
string data()
string ans;
ans.push_back(x + 48);
return ans;
};
40
class DataAddress
public:
vector<MainMemoryAddress> reference;
DataAddress(int n)
reference = vector<MainMemoryAddress>(n);
};
class MainMemory
public:
vector<vector<char>> mainMemory;
vector<vector<MainMemoryAddress>> mainMemoryAddress;
MainMemoryAddress next_empty;
MainMemory()
mainMemoryAddress = vector<vector<MainMemoryAddress>>(main_memory_size,
vector<MainMemoryAddress>(4));
int n = data.length();
41
{
mainMemory[pos.first][pos.second] = data[i];
mainMemoryAddress[pos.first][pos.second].create((pos.first * 4) + pos.second);
address.reference[i] = next_empty;
next_empty.generateNextReference();
int n = address.reference.size();
string ans;
ans.push_back(mainMemory[pos.first][pos.second]);
return ans;
void showMainMemory()
cout << "Value : " << mainMemory[i][j] << " Address : " <<
mainMemoryAddress[i][j].data() << " ";
42
}
};
class CacheMemoryAddress
public:
vector<bool> address;
CacheMemoryAddress()
int i = address_size - 1;
while (r)
i = i - 1;
r = r >> 1;
while (tag)
43
i = i - 1;
int i = address_size - 1;
while (r)
i = i - 1;
r = r >> 1;
i = address_size - 3;
while (tag)
i = i - 1;
int i = address_size - 1;
while (r)
44
i = i - 1;
r = r >> 1;
i = address_size - 3;
while (c)
i = i - 1;
c = c >> 1;
i = address_size - 3 - log2(space);
while (tag)
i = i - 1;
vector<int> position()
string data()
45
{
string ans;
ans.push_back(x + 48);
return ans;
};
class CacheMemory
vector<vector<char>> cahceMemory;
vector<vector<CacheMemoryAddress>> cahceMemoryAddress;
vector<bool> included;
public:
CacheMemory(MainMemory &memory)
cahceMemoryAddress = vector<vector<CacheMemoryAddress>>(cache_memory_size,
vector<CacheMemoryAddress>(4));
46
{
cahceMemoryAddress[i][j].create(i * 4 + j, (i + k * 4) / 4);
int l = 0, r = memory.next_empty.positions().first;
while (included[choose_itr])
cahceMemory[i] = memory.mainMemory[choose_itr];
cahceMemoryAddress[i][j].createFullyAssosiative(i * 4 + j, choose_itr);
47
int l = 0, r = memory.next_empty.positions().first;
int n = cache_memory_size / k;
cahceMemory[j] = memory.mainMemory[choose_itr];
cahceMemoryAddress[j][t].createKSetAssosiative(t, j - i * k, choose_itr / k,
cache_memory_size / k);
void showCacheMemory()
cout << "Value : " << cahceMemory[i][j] << " Address : " <<
cahceMemoryAddress[i][j].data() << " ";
48
}
};
int main()
MainMemory memory;
int k, cnt, y;
while (cnt--)
int n;
string s;
cin >> n;
cin >> s;
DataAddress data(n);
memory.insert(s, data);
CacheMemory cache(memory);
CacheMemory cacheFullyAssosiative(memory);
CacheMemory cacheKWaySetAssosiative(memory);
cout << "Enter index for first element in cache." << endl;
cin >> k;
49
cout << "Enter k in K-Way Set Assosiative" << endl;
cin >> y;
cache.storeDirect(memory, k);
cacheFullyAssosiative.storeFullyAssosiative(memory);
cacheKWaySetAssosiative.storeKSetAssosiative(memory, y);
<< endl;
memory.showMainMemory();
<< endl;
cache.showCacheMemory();
<< endl;
cacheFullyAssosiative.showCacheMemory();
<< endl;
cacheKWaySetAssosiative.showCacheMemory();
return 0;
50
51
52
53
54
55
56