Friday 28 June 2013

8085 program for 8 bit binary division

Here, dividend is of 16 bits and divisor is of 8 bits. Dividend is stored in 8DC1 (LSB) and 8DC2 (MSB), divisor is stored in 8DC3, quotient is in 8DC4 and remainder is in 8DC5.

Mnemonics:

LHLD 8DC1H
LDA 8DC3H
MOV B, A
MVI C, 08

LOOP:
   DAD H
   MOV A, H
   SUB B
   JC AHEAD
   MOV H, A
   INR L

AHEAD:
   DCR C
   JNZ LOOP
   SHLD 8DC4H
   HLT

Observation Table:
Memory Address
Content
8DC1
04H
8DC2
01H
8DC3
03H
8DC4
56H
8DC5
02H


©Dixit Bhatta 2013

Tuesday 25 June 2013

8085 program for multi-byte decimal addition

The counter is stored in 8E00H. The first set of numbers is stored from 8E01H onward, and the second set starts from 8F01H. The sum of numbers in corresponding positions is finally placed in the address of the first set of numbers.

Mnemonics:

LXI H, 8E00H
LXI D, 8F01H
MOV C, M
INX H

LOOP:
   LDAX D
   ADD M
   MOV M, A
   DCR C
   INX H
   INX D
   JNZ LOOP
   HLT

Observation table:
Memory Address
Content Before
Content After
8E00
03H
03H
8E01
12
23
8E02
10
25
8E03
09
20
8F01
11
11
8F02
15
15
8F03
11
11

©Dixit Bhatta 2013

Monday 10 June 2013

C++ Program to Concatenate two strings

/*WAP that has a class with character array as its data member.
One object should contain "Computer Scientists are" and another
should contain " creators of logic". Member function join() should
concatanate two strings by passing two objects as arguments. Display
the concatanated string through a member function. Use constructor
to allocate and intialize the data member. Make one function for
concatanation of two strings.*/

#include <iostream.h>
#include <conio.h>

class concatanate{
char string[50];
   public:
    static count =1;
      concatanate(){ //constructor
      if (count == 1){
          strcpy(string, "Computer Scientists are");
            count++;
         }
         else{
          strcpy(string, " creators of logic.");
            count++;
         }
      }
      //function to concatanate strings
      void join(concatanate a, concatanate b){
      concatanate merged;
         strcat(a.string , b.string);//concatanate a and b strings
         strcpy(merged.string, a.string);
         display(merged);
      }
      //function to display concatanated string
      void display(concatanate a){
      cout<<"Concatanated String is:"<<endl<<endl;
         cout<<a.string;
      }
     
};

void main(){
clrscr();
   concatanate a,b;
   a.join(a,b);
   getch();
}

Thursday 6 June 2013

Basic concept of Static SQL and Dynamic SQL

Static SQL:

Static SQL is the type of SQL in which we cannot change the form of SQL statements unless we change our program. The output of our program will be similar each time based upon the input value. If we use static SQL statements of UPDATE a table, then the table will be updated every time we enter new data. We cannot expect other operations from the program unless we change the whole SQL statements to make them do so.

However, the static SQL can be made flexible to some extent by using so called host variables.

This model can be useful in developing programs that are used to do same tasks time and again, like keeping record of items sold in a store (a billing system).

Dynamic SQL:

Basically, a Dynamic SQL program generates SQL statements or can take SQL statements as input, in form of string, in order to provide flexibility to the program. That is why, it can be considered to be more interactive than Static SQL. In a deeper sense, it is capable of translating the user input into an executable SQL statement. The input is capable of changing the operation performed by the program.

However, there are some statements in SQL that cannot be used dynamically.

This model is useful in programs in which we might need to use multiple kinds of operations on the same data. It is also used in such cases where we may need to use many Static SQL statements, which might prove tedious and lengthy job.  Thus, dynamic SQL provides better flexibility but still due to its complexity, it is slower than Static SQL while execution. 

Tuesday 4 June 2013

Horner's Method

Horner's method is an efficient way of evaluating polynomials and their derivatives at a given point. It is also used for a compact presentation of the long division of a polynomial by a linear polynomial.
A polynomial Pn(x) can be written in the descending order of the powers of x:

Pn(x) = anxn + an-1xn-1 + ... + a1x + a0
or in the ascending order of the exponents:

Pn(x) = a0 + a1x + ... + an-1xn-1 + anxn.
The Horner scheme computes the value Pn(z) of the polynomial P at x = z as the sequence of steps starting with the leading coefficient an using:
bk = z·bk+1 + ak
ck = z·ck+1 + bk
                The next value of the xn in the iterative step is found by,
                xk+1 = xk – (b0/c1), where b0 = Pn(xk) = b0 and c1 = P’n(xk) in shortcut.

Generally, the iteration is continued until the required amount of precision is obtained.

Example: Solve the equation x3+9x2-18 using Horner’s Method where z= x0 = 1.5.
            Here, a0=-18, a1=0, a2=9, and a3=1.
            Starting from a3, b3=c3=a3=1.
            Hence,
            b2 = 9+1x1.5 = 10.5                          c2 = 10.5+1x1.5 = 12
            b1 = 0+10.5x1.5 = 15.75                  c1 = 15.75+12x1.5 = 33.75
            b0 = -18+15.75x1.5 = 5.625                 

            So, x1 = x0 – (b0/c1) = 1.5 – (5.625/33.75) = 1.333
            Þ x1 = z = 1.333
            
            Now, for the new value of z,
            b2 = 9 + 1x1.333 = 10.333                               c1 = 28.881
            b1 = 0+10.333x1.333 = 13.774
            b0 = -18 + 13.774x1.333 = 0.361
            So, x2 = x1 – (b0/c1) = 1.333 – (0.361/28.881) = 1.320
            Þ x2 = z = 1.320

            Again, for new value of z,
            b0 = -0.018           c1 = 28.987
            So, x3 = x2 – (b0/c1) = 1.320 – (-0.018/28.987) = 1.320

Therefore, Approximate Root = 1.320 correct to 3 decimal places. 

Saturday 1 June 2013

Inner Join, Outer Join and Union

Inner Join: Inner join is a way of combining two relations by matching a tuple of a relation with corresponding tuple in next relation, only when they have a common value in a particular attribute.

Outer Join: Outer join is a way of combining two relations by matching a tuple of a relation with corresponding tuple in next relation, but it also includes tuples which have no match in other relation. The tuple which exist on only one relation take null value in remaining attributes. An outer join is either a left-outer join or a right-outer join based on whether all items are taken from relation on left or relation on right respectively.

Union: Union is a way of combining two relations by taking all the elements of both relations.  

Take the following example:

Relation A:
Name
Age
Randy
16
Nathan
12
Sunny
15

Relation B:
Name
Grade
Randy
11
Nathan
7
Yogi
10
Rachel
8

Union of A and B:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
Sunny
15
Sunny
null
Yogi
null
Yogi
10
Rachel
null
Rachel
8
*union has all elements from both relations.

Inner Join:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
*inner join has only elements which can be matched from A to B.

Outer Join:
Name
Age
Name
Grade
Randy
16
Randy
11
Nathan
12
Nathan
7
Yogi
null
Yogi
10
Rachel
null
Rachel
8

*it has even elements which are not in A and this outer join is specifically a right outer join as it includes all items from relation B which we assume to be on the right.