Sunday, 23 September 2018

Computer Architecture & Organization - 1

Register Transfer & Micro-Operation

Register - Collection of individual flip-flops connected in numbers to form different size of registers. Computer Registers are designated by CAPITAL LETTERS.

MAR - Memory Address Register

PC - Program Counter
IR - Instruction Register
R1 - Processor Register


Figure 1.1 : Block Diagram of the Register 
In Register Transfer Language, we can represent Register in various ways as above.

Micro-Operations - The operation executed on data stored in registers are called Micro-Operation. It is an elementary (basic) operation performed on the information stored in one or more registers. The results of the operation may replace the previous binary information of a register or may be transferred to another register. 

Register Transfer Language - It is the symbolic notation used to describe the micro-operation transfer among registers. It is a language of representing the transfer of data from one register to another register.
The term "Register Transfer " implies the availability of hardware logic circuit that can perform a stated micro-operation and transfer the result of the operation to the same or another register. 
A Register Transfer Language is a system for expressing in symbolic form the micro-operation sequences among the register of a digital module 
c = a + b
There are many micro-operations behind the screen like:
(i) Loading the data from Memory
(ii) Putting them in Processor Register
(iii) Loading the new data
(iv) Adding the data to the processor Register
(v) and storing back into the register.

Register Transfer - Information transfer from one register to another is designated in symbolic form by mean of a replacement operation is known as Register Transfer. The below statement R2 <- R1 
Figure 1.2 : Register Transfer
(i) Content of R1 Register is transferred to R2 Register.
(ii) Previous content of R2 Register would be overwritten by the content of R1 Register.
(iii) But that does not mean content of R1 would be deleted.


Figure 1.3 : Bit by Bit Transfer

In the above Figure 1.3 transfer will occur Bit by Bit from Right to Left, that means first Rightmost bit (bit 1 ) will be transfer from Register R1 to Register R2, then second bit from right (bit 0) will be transferred from Register R1 to Register R2 and so on.   

Register Transfer with Control Function -  Control Unit will transfer some signal to the register to perform the load operation or transfer operation. Normally, we want the transfer to occur only under a pre-determined control condition using if - then statement:


if (P = 1) then (R2<- R1)

Where P is a control signal generated in the control section. 
A Control Function is Boolean variable that is equal to 1 or 0. The control function is included in the statement as follows: 
P : R2 <- R1  
Figure 1.4 : Register Transfer with Control Function

(i) Load Input - Enable of R2 Register (Content of R1 Register would not be transferred)
(ii) Transfer will occur at time ( t+ 1) when signal is going to be low. At the end of the clock pulse, transfer will occur.  

Bus and Memory Transfer - We need to connect each of Register with individual Register such that information transfer occurs between these registers. A typical digital Computer has many registers and paths must be provided to transfer information from one register to another. The number of wires will be excessive if separate lines are used between each register and all other registers in the system.


Figure 1.5 : Individual Connection between Three Registers 

Now Consider, if Register D needs to be connected with all three more registers. So you can imagine, how much complex it will becomes. The solution for this is Common Bus System.


Figure 1.6 : 4 - Lines Common Bus  
(i) When input is given as 0 for both select line (S0 and S1).
(ii) 0th lines will be selected. Which means Register A will be selected (A Input is connected).
(iii) Input to the MUX will be A3 A2 A1 A0
(iv) Output will be A3 A2 A1 A0

The below table shows the Register that is selected by the bus for each of the four possible binary values of the select lines:


Table 1.1 : Register Selected as per Inputer Lines

In general,  a bus system will multiplex K registers of n bits each to produce an n-lines common bus. The number of multiplexers needed to construct the bus is equal to n, number of bits in each register. The size of each multiplexer must be k * 1, since it multiplexes k data lines.

(i) No. of Multiplexer - No. of Bits in Register

(ii) Size of Multiplexer - No. of Registers

For example a common bus for 8 Registers of 16 bits requires :

Multiplexers - 16 of ( 8 * 1)
Select Lines - 3
Output - 23 (8 Lines Common Bus)


3- State Buffer - Buffer is having two states, One is Input state and another is Output state. Whatever we give the input we get the same is output but with some delay in the circuit. So buffer gates is used when we want to put some delay in logic circuits. 
We are having try-state buffer that means a buffer with three states. Two states are as usual - one is input, another is output with logic state either 0 or 1. Now we are adding one more state that is High Impedance State, Which makes to buffer gate work as open state circuit. 


Figure 1.7 : 3 - State Buffer


(i) The Control Input determines the output state. When the control input C = 1, the output is enabled and the gate behaves like any conventional buffer, with the output equals to the normal input.
(ii) When the control input C = 0, the output is disabled and the gate goes to a High - Impedance state regardless of the value in the normal input.
(iii) Which means, When control input C = 0, you would not get any output either your input is 0 or 1.


3- State Buffer is used for designing common bus system (like 4 - Line Common Bus). It can be designed using TriState buffer and the decoder.



Figure 1.8 Common Bus System using Tri-State Buffer and Decoder


In this case, we have taken signal bits A0 B0 C0 D. If we are having four bits register, we need to repeat this for A1 B1 C1 D1, A2 B2 C2 D2 and  A3 B3 C3 Dalso. 

(i) Consider  Select Line as S1 – 1 and S0 – 0
(ii) Output will be Line - 2 and rest lines will be 0
(iii) C0 will be input and C0 will be output. 

It is Single State, you can design n number of states depending upon the size of registers. 

Wednesday, 19 July 2017

C Programs


Find below the c programs you all have to write down. 

1 WAP to find the length & breadth of a rectangle.
2 WAP to swap two variables with and without using third variable.
3 WAP to find the reverse of a 4 digit number.
4 WAP to find the sum of the digits of a 4 digit number.
5 "If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402."
6 WAP to find whether the year is leap or not ( Do this with conditional operators).
7 WAP to find the reverse of a 4 digit number and compare it to the original number.
8 If the ages of A, B and C are input through the keyboard, write a program to determine the youngest of the three.
9  Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."
10 WAP to find whether the entered number is Armstrong or not.
11 WAP to find whether the entered number is prime or not.
12 WAP to find the factorial value of of any number.
13 Two number are entered through the keyboard. WAP to find the value of one number raised to the power of another.
14 WAP to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.
15 WAP to print all the Armstrong number between 1 and 500.
16 WAP to enter numbers till the user wants. At the end it should display the count of positive, negative and zeros entered.
17 WAP to find the range of a set of numbers. Range is the difference between the smallest and the biggest number in the list.
18 WAP to print all the prime numbers from 1 to 300.
19 WAP to fill the entire screen with a smiling face. the smiling face has an ASCII value 1.
20 WAP to generate all combinations of 1, 2 and 3.
21 WAP to print the multiplication table of the number entered by the user.
22 Pyramid programs with stars, numbers and alphabets. 
23 Swap the value of two variables using call by value & by reference
24 Factorial, Prime Number, Armstrong number, Fibonacci (first 25 numbers), Sum of digits, Reverse a number , Binary equivalent of a number, Sum of first 25 natural numbers, Prime factors using recursive and non recursive functions.
25 WAP to find the maximum number in a array.
26 WAP that interchanges the odd and even elements of an array.
27 WAP to find out in a[25] how many are positive, how many are negative, how many are even and how many odd.
28 WAP to find if the number to be searched is present in the array and if yes then, display the number of times it appears.
29 WAP to accept only the unique elements in a array.
30 WAP to move the -ve element in one side and +ve on the other side without using third array and order should be same.
31 WAP using pointers to find the smallest number in an array of 25 integers.
32 Implement the Selection Sort, Bubble Sort and Insertion Sort.
33 Linear Search and Binary Search
34 WAP to pick up the largest number from any 5X5 matrix.
35 WAP to obtain transpose of a 4x4 matrix. The transpose of a matrix is obtained by exchanging the elements of each row with the elements of the corresponding column.
36 WAP a program to add two 6x6 matrices.
37 WAP to multiply any two 3x3 matrices.
38 Write your own substring function in the C.
39 WAP to reverse a string.
40 WAP to check whether the entered string is palindrome or not.
41 WAP to sort a set of names stored in an array in alphabetical order.
42 WAP to delete all vowels from a sentence. Assume that the sentence is not more than 80 chars long.
43 WAP that will read a line and delete from it all the occurrences of the word 'the'.
44 WAP that will read a line and replace all spaces with "0x20".
45 WAP that takes a set of names of individuals and abbreviates the first, middle, and other names except the last name by their first letter.
46 WAP which reverse every word in the string.
47 WAP to sort all the elements of a 4x4 matrix.
48 WAP to count the no of times every character occurs in the string.
49 WAP that converts all lowercase characters in a given string to its equivalent uppercase character.
50 WAP that replaces two or more consecutive blanks in a string by a single blank.
51. Write a program that uses an array of pointers to strings str[ ]. Receive two strings str1 and str2 and check if str1 is embedded in any of
the strings in str[ ]. If str1 is found, then replace it with str2.
char *str[ ] = {
We will teach you how to...,
Move a mountain,
Level a building,
Erase the past,
Make a million,
...all through C!
} ;
For example if str1 contains "mountain" and str2 contains "car", then the second string in str should get changed to "Move a car".
52. Write a program to reverse the strings stored in the following array of pointers to strings:
char *s[ ] = {
To err is human...,
But to really mess things up...,
One needs to know C!!
            };
53. Write a program to count the number of occurrences of any two vowels in succession in a line of text. For example, in the sentence
     “Pleases read this application and give me gratuity”  such occurrences are ea, ea, ui.

Monday, 10 October 2016

Install Java in Ubuntu 14.04

Check if Java is already installed in Ubuntu

open a terminal with (Ctrl+Alt+T) and run the command :

java -version

if you seen an output like below : it means you don't have Java installed on your system. 

The program ‘java’ can be found in the following packages:
* default-jre
* gcj-4.6-jre-headless
* openjdk-6-jre-headless
* gcj-4.5-jre-headless
* openjdk-7-jre-headless
Try: sudo apt-get install


if you see an output like below : it means you have Java installed on your system.
 java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)


Install Java in Ubuntu 

Install JRE (Java Runtime Environment) in Ubuntu

Open terminal and run the following commands.

sudo apt-get install default-jre

Install OpenJDK (Jave Development Kit) in Ubuntu 

Open terminal and run the following commands.

sudo apt-get install default-jdk

Install Oracle JDK in Ubuntu

Open terminal and run the following commands of Java8 or Java7 (Couple of files need to get install so make sure that your Internet speed is high.)

Java 8 (Java 1.8)

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default


OR 

 

 Java 7 (Java 1.7)

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java7-set-default

 Now Check with the following command

java -version

You will see the output like:

 java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)


 I hope it helped you to install Java.

Monday, 6 July 2015

Exercise - 1 (C Language Problems)  


Q.1. Consider the function
    find (int x, int y)
    { return ( ( x < y) ? 0 : ( x -y ) ) ; }
Let a , b be two non – negative integers. Which of the following calls finds the possible difference of a and b ?
a) find ( a , b) + find ( b , a )
b) find ( a , find ( a , b ) )
c) a + find ( a , b )
d) b + find ( a , b )

Q.2. The Statement
    if ( myPtr != NULL )
    *myPtr = NULL;
    else
   *myPtr = NULL;
has the same effect as the statement(s)
a) if ( myPtr ) *myPtr = NULL ;
else *myPtr = NULL;
b) *myPtr = NULL;
c) if ( !myPtr ) *myPtr = NULL ;
else *myPtr = NULL;
d) if ( myPtr == NULL ) *myPtr = NULL;
else *myPtr = NULL;

Q.3. The following program fragment
    if ( a= 7)
    printf( “ a is seven ” );
    else
    printf( “ a is not seven ” );
results in the printing of
a) a is seven
b) a is not seven
c) nothing
d) garbage value

Q.4. The following loop
     for ( for i = 1, j = 10 ; i < 6 ; ++ i, --j)
     printf(“%d %d”, i, j);
prints
a) 1 10 2 9 3 8 4 7 5 6
b) 1 2 3 4 5 10 9 8 7 6
c) 1 1 1 1 1 9 9 9 9 9
d) none of the above

Q.5. The following Program
main()
{
    int i=5;
    if (i==5) return;
    else printf(“i is not five ” ) ;
    printf(“over”);
}
results in
a) a syntax error
b) an execution error
c) printing of over
d) execution termination, without printing anything

Q.6. Consider the following program fragment
    if ( a > b )
    printf( “ a > b” );
    else
    printf(“else part”);
    printf(“ a < = b”);
a <= b will be printed if
a) a > b
b) a < b
c) a == b
d) None of the above 

Q.7. Consider the following program 
void main()
{
     int counter = 40;
     for(;counter;)
     printf("Sample");
     printf("%d",counter);
}
What will be the output?
a) 40
b) -40
c) 0
d) None of these

Q.8. What will be the output of following program?
void main()
{
     static char a[ ] = "JAIPUR";
     char * b = "JAIPUR";
     printf("\n %d %d", size of (a), size of (b));
}
a) a = 7, b = 7
b) a = 7, b = 2
c) a = 2, b = 7
d) a = 7, b = 0

Q.9. printf("%d",printf("Hello"));
a) results in a syntax error
b) outputs Hello5
c) outputs garbage
d) prints Hello and terminates abruptly 

Q.10. If n has the value 3 then the output of the statement 
     printf("%d %d", n++ , ++n ); is
a) 3   5
b) 4   5
c) 4   4
d) is implementation dependent

Q.11. printf("%c", 100);
a) prints 100
b) prints the ASCII equivalent of 100
c) prints garbage
d) none of the above

Q.12. printf("%f", 9/5);   prints
a) 1.8
b) 1.0
c) 2.0
d) none of the above

Q.13. The following program fragment
     for( i = 3; i < 15; i += 3 );
     printf("%d", i );
results in 
a) a syntax error
b) an execution error
c) printing of 12
d) printing of 15

Q.14. The following program fragment
    for ( i =1; i <5; ++i )
    if ( i == 3) continue;
    else printf("%d", i );
results in the printing of
a) 1  2  4  5
b) 1  2  4
c) 2  4  5
d) None of these

Q.15. The statement 
     printf("%f", (float) 9/5);
prints
a) 1.8
b) 1.0
c) 2.0
d) none of the above

Q.16. The following program fragment
     if(a = 0)
     printf("a is zero");
     else
     printf("a is not zero");
results in the print of 
a) a is zero
b) a is not zero
c) nothing
d) garbage

Q.17. The following program fragment
     int k = -7
     printf("%d", 0 < !k);
a) prints 0
b) prints a non-zero value
c) is illegal
d) prints an unpredictable value

Q.18. The following program fragment 
     int i  = 107, x = 5;
     printf( (x > 7) ? "%d" : "%c",  i );
results in 
a) an execution error
b) a syntax error
c) printing of k
d) none of the above

Q.19. The following statements
     for( i = 3; i < 15 ;  i += 3)
     {
        printf("%d", i);
        ++i;
      }
will result in the print of 
a) 3  6  9  12
b) 3  6  9  12  15
c) 3  7  11
d) 3  7  11  15

Q.20. The following program fragment
    void main()
    {
      int x = 0;
      while(x <= 10)
      for(;;)
      if(++x%10 == 0)
      break;
      printf("%d", x);
     }
results in
a) printing of 10
b) printing of 20
c) infinite loop
d) none of the above

Friday, 22 May 2015

About Me






The blog provides assignments / practice questions / study material for Computer Science(CS) aspirants. You may connect with me on::  www.nkjaglan.co.in


You can follow / like me on Facebook :: www.facebook.com/nkjaglan

Thanks