Friday, August 12, 2011

Example of structure and Un-structure Programming language



This is one the common question to all the computer Engineers. I tried to find the exact answer of this from internet  but I can not find Perfect answer of the this qestion. so I am writing this Blog.

Please consider Higher level of programming as strucuture programming lanugauge and assembly language as unstructure programming langugae.

Example of the strucutre programming languge In c#

namespace myfirstclass

{
    class Program

    {

        private string name;

        int age;

        int maths;

        int iis;

        int os;

        int total = 300;

        int marks;

        double per;

        void pankil()

        {
            marks = maths + iis + os;

        }

         void krati()

        {

            per = (double)marks / total * 100;

        }

        double showper()

        {

            return per;

        }

        public string sunita

        {

            get

            {

                return name;

            }

            set

            {

                name = value;

            }

        }

        public int agee

        {

            get

            {

                return age;

            }

            set

            {

                age = value;
}
        }
}
    }

    class renu

    {

        static void Main()

        {

            Program p = new Program();

            p.sunita = "Hello";
            p.agee = 10;
            Console.WriteLine("{0} {1}", p.agee, p.sunita);
  }

    }
}

Now Assembly Code for this program. I am showing code of object P only.
 
--- C:\Users\pankil\Documents\Visual Studio 2010\Projects\myfirstclass\myfirstclass\Program.cs

        {

00000000  push        ebp

00000001  mov         ebp,esp

00000003  push        edi

00000004  push        esi

00000005  push        ebx

00000006  sub         esp,48h

00000009  lea         edi,[ebp-38h]

0000000c  mov         ecx,0Bh

00000011  xor         eax,eax

00000013  rep stos    dword ptr es:[edi]

00000015  xor         eax,eax

00000017  mov         dword ptr [ebp-1Ch],eax

0000001a  cmp         dword ptr ds:[0018313Ch],0

00000021  je          00000028

00000023  call        6D0A5ADF

00000028  xor         edx,edx

0000002a  mov         dword ptr [ebp-3Ch],edx

0000002d  nop

            Program p = new Program();

0000002e  mov         ecx,18395Ch

00000033  call        FFF41FB0

00000038  mov         dword ptr [ebp-40h],eax

0000003b  mov         ecx,dword ptr [ebp-40h]

0000003e  call        FFF9BFF8

00000043  mov         eax,dword ptr [ebp-40h]

00000046  mov         dword ptr [ebp-3Ch],eax

            p.sunita = "Hello";

00000049  mov         edx,dword ptr ds:[03652030h]

0000004f  mov         ecx,dword ptr [ebp-3Ch]

00000052  cmp         dword ptr [ecx],ecx

00000054  call        FFF9BFE0

00000059  nop

            p.agee = 10;

0000005a  mov         ecx,dword ptr [ebp-3Ch]

0000005d  mov         edx,0Ah

00000062  cmp         dword ptr [ecx],ecx

00000064  call        FFF9BFF0

00000069  nop

            Console.WriteLine("{0} {1}", p.agee, p.sunita);

0000006a  mov         eax,dword ptr ds:[03652034h]

00000070  mov         dword ptr [ebp-44h],eax

00000073  mov         ecx,dword ptr [ebp-3Ch]

00000076  cmp         dword ptr [ecx],ecx

00000078  call        FFF9BFE8

0000007d  mov         dword ptr [ebp-48h],eax

00000080  mov         ecx,6C532978h

00000085  call        FFF41FB0

0000008a  mov         dword ptr [ebp-4Ch],eax

0000008d  mov         eax,dword ptr [ebp-4Ch]

00000090  mov         edx,dword ptr [ebp-48h]

00000093  mov         dword ptr [eax+4],edx

00000096  mov         eax,dword ptr [ebp-4Ch]

00000099  mov         dword ptr [ebp-50h],eax

0000009c  mov         ecx,dword ptr [ebp-3Ch]

0000009f  cmp         dword ptr [ecx],ecx

000000a1  call        FFF9BFD8

000000a6  mov         dword ptr [ebp-54h],eax

000000a9  push        dword ptr [ebp-54h]

000000ac  mov         edx,dword ptr [ebp-50h]

000000af  mov         ecx,dword ptr [ebp-44h]

000000b2  call        6C2CD504

000000b7  nop

        }

000000b8  nop

000000b9  lea         esp,[ebp-0Ch]

000000bc  pop         ebx

000000bd  pop         esi

000000be  pop         edi

000000bf  pop         eb