0% found this document useful (0 votes)
45 views79 pages

Record COA.1730813930729

Uploaded by

nmadishe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views79 pages

Record COA.1730813930729

Uploaded by

nmadishe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 79

GITAM

Deemed to be University
Hyderabad Campus

Laboratory Record Book

Name of the Student: Navaneeth


Madishetty
Pin No: 2023003796
Department:Computer Science and
Business Systems
Laboratory: Computer Organization &
Architecture
GITAM
Deemed to be University
Hyderabad Campus

Certified that this is the bonafide record of


practical work done by Mr./Ms. Madishetty
Navaneeth with Reg. 2023003796 of B. Tech
Computer Science Engineering branch in
Computer Organization & Architecture
Laboratory of Department of during the
academic year 2023-2024.

Faculty I/c.
Date: 04 -11-2024 Head
of the Department
INDEX

S.No Topic Date Page Marks Remarks


No
1 Introduction to Circuit
03/07/2024
verse
2 Basics of Circuitverse 03/07/2024
3 Understanding Circuit
Elements, Properties of I/P 05/07/2024
and O/P
4 Implemented Gates using
05/07/2024
I/P and O/P
5 Adders 19/07/2024
6 Random , Counter 26/07/2024
7 Shift Registers 07/08/2024
8 Gates 09/08/2024
9 Flip Flops 09/08/2024
10 Ram and Address 21/08/2024
11 3-bit adder and Multiplexer 30/08/2024
12 Register and counter 30/08/2024
Circuits
13 Introduction to NASM 25/10/2024
14 Assembly Language 25/10/2024
programs
15 Logic Gates 25/10/2024
16 C++ Programs 25/10/2024
17
18
19
20
 INTRODUCTION TO CIRCUITVERSE:

CircuitVerse is an open-source platform


designed for learning and experimenting with
digital circuits. It provides a user-friendly,
online simulator where students, educators,
and electronics enthusiasts can create,
simulate, and share digital circuit designs.
Users can build a variety of circuits, ranging
from basic gates and combinational logic to
more complex sequential circuits.
CircuitVerse also includes a collaborative
aspect, allowing users to share projects, fork
others’ designs, and work on circuit projects
together. It supports interactive learning
through step-by-step simulations and has an
extensive library of circuit components,
making it ideal for both self-paced learning
and classroom use. Additionally, CircuitVerse
offers a rich online community, tutorials, and
documentation to help users at all levels get
started with digital electronics.

 BASIC GATES

1. AND GATE

2. OR GATE
3. NOT GATE

4. NAND GATE

5. NOR GATE

6. XOR GATE

7. XNOR GATE
 LOGIC GATES

1.~A\/B

2.~A/\B

3.
4.~A\/~B

5.~A /\~B

6.A /\ B \/ C

7.A /\ ~B /\ C
8.A \/ B + C
ADDER CIRCUITS

1. 2-BIT ADDER

2. 4-BIT ADDER
3. 8-BIT ADDER

SUBTRACTOR
MULTIPLIER

DIVIDERS
\

SHIFTERS
1. Logical left shift

2. Logical right shift


3. Arithmetic right shift

4. Rotate left
5. Rotate right

NEGATOR
COMPARATOR

BIT ADDER
BIT ADDER
GATES
ODD PARITY

EVEN PARITY
CONTROLLED BUFFER

PLEXERS
BIT SELECTOR
FLIPFLOPS

1.D-Flip flops

2.T-Flip flops
3.J-K flip-flops
4.S-R flip flop

RAM & ADDRESS


1. Half adder

2. Full adder

3. RAM
4.

4-BIT REGISTER
 NASM Installation
Step1. Create new folder in C drive and name as
NASM.
Step2. Download NASM zip folder and place it in
NASM folder and extract in NASM folder by
clicking Extract here.
Step3. Download DOSBOX and place DOSBOX file in
NASM folder and download it.
Step4. Open a new text document (notepad)in NASM
folder and write assemble program later saveas
with asm extension example firstprogram.asm.
Step5. To run a program on DOSBOX, double click
on DOSBOX icon. It opens command prompt with Z
drive by default.
Step6. Convert Z drive to C drive because folder
NASM in C drive by using commands
1. MOUNT C C:\NASM
2. C:
Step7. To run firstprogram.asm then fire the
commands
1. nasm test.asm -o t.com (-o output)
2. afd t.com (It opens program execution
window)
3. Press f2 in execution window for each
instruction of a program.
4. After completing, type quit in
execution window.
 ASSEMBLY CODE LANGUAGE PROGRAM

1. ADDITION:

[org 0x100]
mov ax, 5
add ax, 3
mov ax, 0x4c00
int 0x21
2. SUBTRACTION:

[org 0x100]

mov ax, 10
sub ax, 4

mov ax, 0x4c00

int 0x21
3. MULTIPLICATION:

[org 0x100]

mov ax, 2
imul ax,4

mov ax, 0x4c00


int 0x21
4. DIVISION:

[org 0x100]

mov ax, 10
mov bx, 2
idiv bx
cdq

mov ax, 0x4c00


int 0x21
5. BITWISE OR:
[org 0x100]

mov ax, 5
or ax, 3

mov ax, 0x4c00


int 0x21
6. BITWISE OR:

[org 0x100]

mov ax, 5
and ax, 3

mov ax, 0x4c00


int 0x21
7. GCD

[org 0x100]

mov ax, 48
mov bx, 18

gcd_loop:
cmp bx, 0
je gcd_done
cdq
idiv bx
mov ax, bx
mov bx, dx
jmp gcd_loop

gcd_done:

mov ax, 0x4c00


int 0x21
8. Even or Odd:

[org 0x100]

mov ax, 5
test ax, 1
jz even

odd:
; Do something if odd (e.g., set a flag)
jmp done

even:
; Do something if even

done:
mov ax, 0x4c00
int 0x21
9. Prime Number:

[org 0x100]

mov ax, 7
mov cx, 2

prime_loop:
cmp cx, ax
jge is_prime

mov dx, 0
mov bx, cx
div bx
cmp dx, 0
je not_prime
inc cx
jmp prime_loop

is_prime:
; Handle prime case
jmp done

not_prime:
; Handle non-prime case

done:
mov ax, 0x4c00
int 0x21
10. Fibonacci Sequence:

[org 0x100]

; Input: n = 5, Output: nth Fibonacci number in ax


mov cx, 5 ; The nth Fibonacci number to calculate
mov ax, 0 ; Starting value for Fibonacci sequence
mov bx, 1 ; Second value for Fibonacci sequence

fib_loop:
cmp cx, 1
jle fib_done
add ax, bx ; Add previous two Fibonacci numbers
xchg ax, bx ; Swap ax and bx
dec cx
jmp fib_loop

fib_done:
; Move the result to another register to preserve it
mov dx, ax ; Store the Fibonacci result in dx

; Now set up ax to terminate the program without


changing dx
mov ax, 0x4c00
int 0x21 ; Terminate program
11. Swap two numbers:

[org 0x100]
mov al, 5
mov bl, 10
; Swap values
xchg al, bl
; Exit program
mov ax, 0x4c00
int 0x21
12. Maximum of two numbers:

[org 0x100]
mov al, 5
mov bl, 10
; Compare numbers
cmp al, bl
jge store_al
mov al, bl
store_al:
; Exit program
mov ax, 0x4c00
int 0x21
13. Factorial of number:

[org 0x100]
mov al, 5
mov bl, al
dec bl
factorial_loop:
cmp bl, 0
je end_factorial
mul bl
dec bl
jmp factorial_loop
end_factorial:
; Exit program
mov ax, 0x4c00
int 0x21
LOGIC GATES:

1. AND gate:
C programs:

1.Write a C program to convert characters to ASCII and


ASCII to characters.
#include <stdio.h>

void charToAscii() {
char ch;
printf("Enter a character: ");
scanf(" %c", &ch); // Read a single character with a
space before %c to ignore whitespace
printf("The ASCII value of '%c' is %d\n", ch, (int)ch);
}

void asciiToChar() {
int ascii;
printf("Enter an ASCII value (0-127): ");
scanf("%d", &ascii);

if (ascii >= 0 && ascii <= 127) {


printf("The character for ASCII value %d is '%c'\n",
ascii, (char)ascii);
} else {
printf("Invalid ASCII value. Please enter a value
between 0 and 127.\n");
}
}
int main() {
int choice;

while (1) {
printf("\nMenu:\n");
printf("1. Convert character to ASCII\n");
printf("2. Convert ASCII to character\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
charToAscii();
break;
case 2:
asciiToChar();
break;
case 3:
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice. Please select 1, 2, or 3.\
n");
}
}
}

Output:
2. Write a C program to convert Binary to Hexadecimal and

vice versa.

#include <stdio.h>
#include <string.h>
#include <math.h>

void binaryToHexadecimal() {
char binary[65];
int decimal = 0;
printf("Enter a binary number: ");
scanf("%s", binary);

// Convert binary to decimal


int length = strlen(binary);
for (int i = 0; i < length; i++) {
if (binary[i] == '1') {
decimal += pow(2, length - i - 1);
} else if (binary[i] != '0') {
printf("Invalid binary number.\n");
return;
}
}

// Convert decimal to hexadecimal


printf("Hexadecimal: %X\n", decimal);
}

void hexadecimalToBinary() {
char hex[17];
int decimal;
printf("Enter a hexadecimal number: ");
scanf("%s", hex);

// Convert hexadecimal to decimal


sscanf(hex, "%x", &decimal);

// Convert decimal to binary


printf("Binary: ");
for (int i = 31; i >= 0; i--) {
printf("%d", (decimal >> i) & 1);
}
printf("\n");
}

int main() {
int choice;
while (1) {
printf("\nMenu:\n");
printf("1. Convert Binary to Hexadecimal\n");
printf("2. Convert Hexadecimal to Binary\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
binaryToHexadecimal();
break;
case 2:
hexadecimalToBinary();
break;
case 3:
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice. Please select 1, 2, or 3.\
n");
}
}
}

Output:
3. Convert Binary to Octal and Vice Versa

#include <stdio.h>
#include <string.h>
#include <math.h>

void binaryToOctal() {
char binary[65];
int decimal = 0;
printf("Enter a binary number: ");
scanf("%s", binary);

// Convert binary to decimal


int length = strlen(binary);
for (int i = 0; i < length; i++) {
if (binary[i] == '1') {
decimal += pow(2, length - i - 1);
} else if (binary[i] != '0') {
printf("Invalid binary number.\n");
return;
}
}

// Convert decimal to octal


printf("Octal: %o\n", decimal);
}

void octalToBinary() {
int octal;
int decimal = 0, i = 0;

printf("Enter an octal number: ");


scanf("%o", &octal);

// Convert octal to decimal


decimal = octal;

// Convert decimal to binary


printf("Binary: ");
for (int i = 31; i >= 0; i--) {
printf("%d", (decimal >> i) & 1);
}
printf("\n");
}

int main() {
int choice;
while (1) {
printf("\nMenu:\n");
printf("1. Convert Binary to Octal\n");
printf("2. Convert Octal to Binary\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
binaryToOctal();
break;
case 2:
octalToBinary();
break;
case 3:
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice. Please select 1, 2, or 3.\
n");
}
}
}
Output:
4. Convert Binary to Decimal and Vice Versa

#include <stdio.h>
#include <string.h>
#include <math.h>

void binaryToDecimal() {
char binary[65];
int decimal = 0;
printf("Enter a binary number: ");
scanf("%s", binary);

// Convert binary to decimal


int length = strlen(binary);
for (int i = 0; i < length; i++) {
if (binary[i] == '1') {
decimal += pow(2, length - i - 1);
} else if (binary[i] != '0') {
printf("Invalid binary number.\n");
return;
}
}
printf("Decimal: %d\n", decimal);
}

void decimalToBinary() {
int decimal;
printf("Enter a decimal number: ");
scanf("%d", &decimal);

// Convert decimal to binary


printf("Binary: ");
for (int i = 31; i >= 0; i--) {
printf("%d", (decimal >> i) & 1);
}
printf("\n");
}

int main() {
int choice;
while (1) {
printf("\nMenu:\n");
printf("1. Convert Binary to Decimal\n");
printf("2. Convert Decimal to Binary\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
binaryToDecimal();
break;
case 2:
decimalToBinary();
break;
case 3:
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice. Please select 1, 2, or 3.\
n");
}
}
}

Output:
5. AND and OR Gate

#include <stdio.h>

void andGate(int a, int b) {


int result = a & b;
printf("AND Gate: %d AND %d = %d\n", a, b, result);
}

void orGate(int a, int b) {


int result = a | b;
printf("OR Gate: %d OR %d = %d\n", a, b, result);
}

int main() {
int a, b;
printf("Enter first binary input (0 or 1): ");
scanf("%d", &a);
printf("Enter second binary input (0 or 1): ");
scanf("%d", &b);
// Validate inputs
if ((a != 0 && a != 1) || (b != 0 && b != 1)) {
printf("Invalid input! Please enter 0 or 1.\n");
return 1;
}
andGate(a, b); // Perform AND operation
orGate(a, b); // Perform OR operation
return 0;
}
Output:

6. AND and NAND Gate:

#include <stdio.h>

void andGate(int a, int b) {


int result = a & b;
printf("AND Gate: %d AND %d = %d\n", a, b, result);
}

void nandGate(int a, int b) {


int result = !(a & b); // Perform NAND operation by
inverting the AND result
printf("NAND Gate: %d NAND %d = %d\n", a, b,
result);
}
int main() {
int a, b;
printf("Enter first binary input (0 or 1): ");
scanf("%d", &a);
printf("Enter second binary input (0 or 1): ");
scanf("%d", &b);
// Validate inputs
if ((a != 0 && a != 1) || (b != 0 && b != 1)) {
printf("Invalid input! Please enter 0 or 1.\n");
return 1;
}
andGate(a, b); // Perform AND operation
nandGate(a, b); // Perform NAND operation
return 0;
}
Output:
7. XOR and OR Gate:

#include <stdio.h>

void xorGate(int a, int b) {


int result = a ^ b; // XOR operation
printf("XOR Gate: %d XOR %d = %d\n", a, b, result);
}

void orGate(int a, int b) {


int result = a | b; // OR operation
printf("OR Gate: %d OR %d = %d\n", a, b, result);
}

int main() {
int a, b;
printf("Enter first binary input (0 or 1): ");
scanf("%d", &a);
printf("Enter second binary input (0 or 1): ");
scanf("%d", &b);
// Validate inputs
if ((a != 0 && a != 1) || (b != 0 && b != 1)) {
printf("Invalid input! Please enter 0 or 1.\n");
return 1;
}
xorGate(a, b); // Perform XOR operation
orGate(a, b); // Perform OR operation
return 0;
}
Output:

8. .NAND and NOR Gate:

#include <stdio.h>

void nandGate(int a, int b) {


int result = !(a & b); // Perform NAND operation by
inverting the AND result
printf("NAND Gate: %d NAND %d = %d\n", a, b,
result);
}

void norGate(int a, int b) {


int result = !(a | b); // Perform NOR operation by
inverting the OR result
printf("NOR Gate: %d NOR %d = %d\n", a, b, result);
}
int main() {
int a, b;
printf("Enter first binary input (0 or 1): ");
scanf("%d", &a);
printf("Enter second binary input (0 or 1): ");
scanf("%d", &b);
// Validate inputs
if ((a != 0 && a != 1) || (b != 0 && b != 1)) {
printf("Invalid input! Please enter 0 or 1.\n");
return 1;
}
nandGate(a, b); // Perform NAND operation
norGate(a, b); // Perform NOR operation
return 0;
}
Output:
9. Left and Right Shift

#include <stdio.h>

void leftShift(int num, int shift) {


int result = num << shift;
printf("Left Shift: %d << %d = %d\n", num, shift,
result);
}

void rightShift(int num, int shift) {


int result = num >> shift;
printf("Right Shift: %d >> %d = %d\n", num, shift,
result);
}

int main() {
int num, shift;

printf("Enter an integer: ");


scanf("%d", &num);
printf("Enter the number of positions to shift: ");
scanf("%d", &shift);

leftShift(num, shift); // Perform left shift operation


rightShift(num, shift); // Perform right shift operation

return 0;
}
Output:

10. Arithmetic Right Shift

#include <stdio.h>

void arithmeticRightShift(int num, int shift) {


int result = num >> shift;
printf("Arithmetic Right Shift: %d >> %d = %d\n", num,
shift, result);
}

int main() {
int num, shift;

printf("Enter an integer: ");


scanf("%d", &num);

printf("Enter the number of positions to shift: ");


scanf("%d", &shift);
arithmeticRightShift(num, shift);

return 0;
}
Output:

11. Arithmetic Right and Left Shift

#include <stdio.h>

void arithmeticRightShift(int num, int shift) {


int result = num >> shift;
printf("Arithmetic Right Shift: %d >> %d = %d\n", num,
shift, result);
}

void arithmeticLeftShift(int num, int shift) {


int result = num << shift;
printf("Arithmetic Left Shift: %d << %d = %d\n", num,
shift, result);
}
int main() {
int num, shift;

printf("Enter an integer: ");


scanf("%d", &num);

printf("Enter the number of positions to shift: ");


scanf("%d", &shift);

arithmeticLeftShift(num, shift); // Perform arithmetic


left shift
arithmeticRightShift(num, shift); // Perform
arithmetic right shift

return 0;
}
Output:
12. Circular Right and Circular Left Shift

#include <stdio.h>

#define BITS 32 // Assuming 32-bit integers

unsigned int circularLeftShift(unsigned int num, int shift)


{
shift %= BITS; // To handle cases where shift > 32
return (num << shift) | (num >> (BITS - shift));
}

unsigned int circularRightShift(unsigned int num, int


shift) {
shift %= BITS; // To handle cases where shift > 32
return (num >> shift) | (num << (BITS - shift));
}

int main() {
unsigned int num;
int shift;

printf("Enter an integer: ");


scanf("%u", &num);

printf("Enter the number of positions to shift: ");


scanf("%d", &shift);

printf("Circular Left Shift: %u << %d = %u\n", num,


shift, circularLeftShift(num, shift));
printf("Circular Right Shift: %u >> %d = %u\n", num,
shift, circularRightShift(num, shift));

return 0;
}
Output:

You might also like