You are on page 1of 8

NAME: - Rakshit- Bhari

BRANCH: -CSE

ROLLNO: -2021A1R084

COURSE NAME: - COMPUTER ORGANISATION AND ARCHITECTURE

COURSE CODE: - COM-403

SUBMITTED TO: -MS. VISHALIKA

ASSIGNMENT NO: -1
Q1: Construct a bus system with multiplexers for 6 registers. Write a code
using C language to show their hardware implementation.
Sol.

Common Bus System for 6 registers are as follows:

Fig: 4 Line Common Bus


C program for hardware implementation of the same:

#include <stdio.h>
#define REG_NUM 6
int main() {
int regs[REG_NUM]; // array to hold register values
int bus; // value on the common bus
int mux_sel; // multiplexer selection input
// initialize register values
for (int i = 0; i< REG_NUM; i++) {
printf("Enter the integer to be stord on %d multiplexer: ", i+1);
scanf("%d",&regs[i]);
}
// main loop
while (1) {
// read multiplexer selection input
printf("Enter the multiplexer selection input (0-5): ");
scanf("%d", &mux_sel);
// read value from the selected register
if( mux_sel> 5 || mux_sel< 0){
printf("Out of range!!!!!!!!");
break;
}
else{
bus = regs[mux_sel];
}
// output value on the common bus
printf("Value on the common bus: %d\n", bus);
}
return 0;
}
Q2: Implement the Circular Shift Microoperation using C++.
Sol. #include <iostream>
#include <bitset>
using namespace std;

// Circular shift left function


bitset<8>circularShiftLeft(bitset<8> input, int shift) {
bitset<8>output;
for (int i = 0; i< 8; i++) {
output[(i + shift) % 8] = input[i];
}
return output;
}

// Circular shift right function


bitset<8>circularShiftRight(bitset<8> input, int shift) {
bitset<8>output;
for (int i = 0; i< 8; i++) {
output[(i - shift + 8) % 8] = input[i];
}
return output;
}

int main() {
// Test circular shift left
int B1,S1;
cout<<"Enter the decimal number: ";
cin>>B1;
cout<<"How many bits you want to shift: ";
cin>>S1;
bitset<8> input1(B1);
bitset<8> output1 = circularShiftLeft(input1, S1);
cout<< "Circular shift left of " << input1 << " by " <<S1<<" bits are:
"<<output1 <<endl;
// Test circular shift right
bitset<8> input2(B1);
bitset<8> output2 = circularShiftRight(input2, S1);
cout<< "Circular shift right of " << input2 << " by " <<S1<<" bits are:
"<<output2 <<endl;

return 0;
}

This code defines two functions circularShiftLeft and circularShiftRight which


implement the circular shift left and right microoperations respectively. Both
functions take a bitset<8> input and an integer shift which determines the
number of bits to shift. The functions return a bitset<8> output which contains
the shifted bits.
The circularShiftLeft function implements the circular shift left microoperation
by looping through each bit in the input and copying it to the output shifted by
shift bits. The % 8 operation ensures that the shifting is circular, i.e., bits that
are shifted off the end of the byte are wrapped around to the beginning.
The circularShiftRight function is similar tocircularShiftLeft but with a slightly
different shift calculation. Here, the - shift operation is used instead of + shift to
shift the bits to the right. The + 8 and % 8 operations ensure that the shifting is
still circular even when shifting bits to the right.
Q3: A computer uses a memory unit with 256K words of 32 bits each. A
binary instruction code is stored in one word memory. The instruction has
four parts: an indirect bit, an operation code, a register code part to specify
one of 64 registers, and an address part.
1. How many bits are there in operation code, the register code part,
and the address part?
2. Draw the instruction word format and indicate the number of bits in
each part.
3. How many bits are there in the data and address inputs of memory?

Sol.The memory unit has 256 thousand words of 32 bits. This means that the
totalmemory size is:
256 thousand words x 32 bits/word = 8,388,608 bits

The instruction is stored in one word of memory and has four parts: an
indirect bit, an opcode, a register code part to specify one of the 64 registers,
and an address part.

The number of bits in each part is as follows:

Indirect bit: 1 bit

Opcode: Complete instruction size - (indirect bit size + register code size +
address part size).
=> 32 - (1 + 6 + 18) = 7 bits are used to determine the opcode.

Register Code: Since there are 64 registers, we need log2(64) = 6 bits to


specify the register.
Address part: Since the memory unit has 256K words, we need log2(256K) =
log2(262144) = 18 bits to specify the address.

 Indirect Bit(1-bit)
 Operation code (7-bits)
 Register code(6-bits)
 Address Part(18-bits)

The number of bits in the data and address inputs of the memory is the same
as the word size of the memory unit, which in this case is 32 bits.

You might also like