Featured Post

Showing posts with label Computer Organisation and Computer Architecture. Show all posts
Showing posts with label Computer Organisation and Computer Architecture. Show all posts

Friday, October 21, 2016

Subtraction of two numbers using one's complement and two's complement


Addition of two numbers:

                      Find the addition of 10 an 8?


           Let A=10------------>        1 0 1 0
           Let B=8-------------->    + 1 0 0 0         
                                                  1 0 0 1 0      

    Decimal Equivalent of 18 is 10010  which is equivalent to 10+8=18

   problem no 1:  Find the subtraction value of 10 and 9?
 
                         When subtracting a number from another number ( or if a number is negative) then we use one's complement and two's complement notations for a negative number and add the negative number in 1's and 2's complement numbers to the first number.

One's Complement: The one's complement of a number can be obtained by changing the binary digits 0 and 1 of a number  to 1 and 0 respectively.

Two's Complement: First find the one's complement of a given number and then add binary number 1 to one's complement


Subtracting two numbers using one's complement number

Let A= 10-------------------->     1010
Let B= -9--------------------->

    Binary   value    of            9    is            1 0 0 1        
    1's     complement     of    8    is             0 1 1 0

Now   A =     1  0  1  0                 ( total four digits)
           B =  + 0  1  1  0                 (total four digits)
   Result     1  0  0  0  0               (total five digits )
               
In this case the left most value( extra bit) is added to the result

     Result        0   0   0   0
                                 +   1  
                        0  0   0   1                    

The binary equivalent of 0 0 0 1 is   decimal value +1   (   9 - 8 =1)

Problem number 2: Find the value of 8 - 10 using one's complement?

The binary value of 8 is  1000


For -10 value  first we fine one' s complement value i.e., -10=0101

Let    A=  8 -------------->   1 0 0 0
         b= -10

Binary value of 10 is                                      1 0 1 0
One's complement of 10 is                             0 1 0 1



Now we add two's complement of 10 to binary value of 8

       A----------------->          1 0 0 0
      B------------------>      + 0 1 0 1 
                                            1 1 0 1

One at the left most bit indicates negative and the result is in one's complement form

The one's complement of 101 is 010  i.e., 2 and the final value is -2 ( 8 -10 =-2)

Problem no 3: Find the value of 10 -  9 using 2's complement

Two's Complement: First find the one's complement of a given number and then add binary number 1 to one's complement


 Binary   value    of            10      is               1 0 1 0      
    1's     complement     of   9   is                   0 1 1 0
    2's     complement     of   9  is                   0 1 1 1

Now   A =     1  0  1  0                 ( total four digits)
           B =  + 0  1  1 1                  (total four digits)
                  1  0  0  0  1                   (total five digit)

In this case ignore the left most bit, so the final result is 0 0 0 1   (  9 - 8 = +1)
                             

Problem no 4:  Find the value of 9 - 10

Binary   value    of                9     is                1 0 0 1      
    1's     complement     of    10    is                0 1 0 1
    2's     complement     of    10     is               0 1 1 0

Now   A =     1 0 0 1                 ( total four digits)
           B =  + 0 1 1 0                 (total four digits)
                   1 1 1 1 1            (total five digit)
In this case ignore the left most bit, so now the partial result is 1 1 1 1
And left most bit in 1 1 1 1 is 1 indicating that the result is negative and final result is in 2's complement form

The 2's complement of 1 1 1 1

                1's complement of 1 1 1 1 is            0 0 0 0

                2's complement of 1 1 1 1 is            0 0 0 0
                                                                             +   1   
                                                                          0 0 0 1
So the final result is -1  (9 -10 = -1)


Signed representation, one's complement of a number. two's complement of a number. 1's complement of a number. 2's complement of a number . adding two binary numbers, adding two binary numbers using 1's complement and 2' complement, Modi banned 500rs and 1000rs. new 500rs notes, new 1000rs note, new 2000 rupee note, new currency with chip enabled, 2000rs note with chip enabled.logic behind banning,hange, tax exemption on money, tax exemption on toll gate free, ATMS not wroking , firday new notes released ,  why 500 and 1000rs notes banned  abdul kalam photo on 200rs n otes, tax on currency exc500 100rs notes clab sample programs subtracting one number from second number using 1's complement and 2's complement. signed representation, signed magnitude representation 




Wednesday, October 5, 2016

Role of Stack in Computer Organization




         A stack is a data structure where we can store a group of items. Elements are added and removed from the top of the stack. i.e., the element to be removed is top of the stack. Stack follows Last In First Out(LIFO) order in adding and deleting the elements. Adding an element is called push operation and removing the element is called pop operation.

Consider a scenario like:
                 
                           Main memory capacity is 2048 MB. Stack occupies memory location from 2000 to 1500 location. Initially the stack is empty . Lets have a stack pointer whose name is SP to point the elements in the stack.

Note: When we are adding elements to a stack the stack moves towards lower memory locations i.e., stack moves form location 2000 to 1500.

push operation:
   
                         Adding an element to a stack is called push operation. When adding an element to a stack we need to decrement the stack pointer SP. Then after decrementing the stack the element to be pushed on to the new location pointer to by stack pointer SP.



For example we want to place a data item A on to stack.

                                    SP=SP-1
                                    MOVE A,[SP]


Note: [SP]  stands for value at address pointed to by SP

The above assembly language instructions can be written in a single instruction like

                                     MOVE A,-[SP]          

Now SP is pointing to new data item A

POP Operation:  

                       Removing an element from the stack is called pop operation. Removing an element means we are not physically removing the item from the stack but we just incrementing the stack pointer to show the next top element. To implement pop operation first we need to copy the item and then just increment the stack pointer.

                                            MOVE [SP],TEMP
                                            SP=SP+1

The above assembly language instruction can be written in a single instruction as


                                MOVE [SP]+,TEMP

Now the Stack pointer SP is pointing to next top element and removed element is in TEMP variable.





role of stack and queue in computer organisation, push and pop operation in CO, STACKFULL, STACK EMPTY, branch routines, rotate instructions, shift instructions arithmetic instructions, instruction and instruction sequencing. addressing modes, machine instructions. logic instructions, machine instructions. buses, DMA, generation of computers, data bus, control bus, address bus,