computer science - paper i & ii.pdf

75
Computer Science - Journal Paper I - Software Visual Basic Program No 1 : Program to calculate Area of circle and Rectangle Private Sub area_circle_Click() Text2.Text = 3.14 * Val(Text1.Text) * Val(Text1.Text) End Sub Private Sub area_rect_Click() Text5.Text = Val(Text3.Text) * Val(Text4.Text) End Sub Private Sub circle_Click() Shape2.Visible = False Label2.Visible = False Label3.Visible = False Text3.Visible = False Text4.Visible = False Text5.Visible = False area_rect.Visible = False Shape1.Visible = True Label1.Visible = True Text1.Visible = True Text2.Visible = True area_circle.Visible = True End Sub Private Sub clear_Click() Text1.Text = "" Text2.Text = "" Text3.Text = ""

Upload: aakarsh123456

Post on 18-Jul-2016

50 views

Category:

Documents


6 download

TRANSCRIPT

Computer Science - Journal

Paper I - Software

Visual Basic

Program No 1 : Program to calculate Area of circle and Rectangle

Private Sub area_circle_Click() Text2.Text = 3.14 * Val(Text1.Text) * Val(Text1.Text) End Sub Private Sub area_rect_Click() Text5.Text = Val(Text3.Text) * Val(Text4.Text) End Sub Private Sub circle_Click() Shape2.Visible = False Label2.Visible = False Label3.Visible = False Text3.Visible = False Text4.Visible = False Text5.Visible = False area_rect.Visible = False Shape1.Visible = True Label1.Visible = True Text1.Visible = True Text2.Visible = True area_circle.Visible = True End Sub Private Sub clear_Click() Text1.Text = "" Text2.Text = "" Text3.Text = ""

Text4.Text = "" Text5.Text = "" End Sub Private Sub exit_Click() End End Sub Private Sub rectangle_Click() Shape2.Visible = True Label2.Visible = True Label3.Visible = True Text3.Visible = True Text4.Visible = True Text5.Visible = True area_rect.Visible = True Shape1.Visible = False Label1.Visible = False Text1.Visible = False Text2.Visible = False area_circle.Visible = False End Sub

Program No 2 : Program using Drag-Drop Private Sub Form_Load() Picture1.BackColor = vbRed End Sub Private Sub object_DragDrop(Source As Control, X As Single, Y As Single) Picture1.BackColor = vbBlue End Sub Private Sub object_DragOver(Source As Control, X As Single, Y As Single, State As Integer) Picture1.BackColor = vbGreen End Sub Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single) Picture1.BackColor = vbBlue End Sub Private Sub Picture1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) Picture1.BackColor = vbGreen End Sub

Program No 3 : Program using List Box Private Sub addl1_Click() Dim str1 As String str1 = InputBox("please enter name of new item") List1.AddItem str1 End Sub Private Sub addl2_Click() str2 = InputBox("please enter name of new item") List2.AddItem str2 End Sub Private Sub backward_Click() List1.AddItem List2.Text End Sub Private Sub end_Click() End End Sub Private Sub forward_Click() List2.AddItem List1.Text End Sub Private Sub reml1_Click() Dim r1 r1 = List1.ListIndex List1.RemoveItem r1 End Sub Private Sub reml2_Click() Dim r2 r2 = List2.ListIndex List2.RemoveItem r2 End Sub

Program No 4 : Program to declare Result using Case Condition

Private Sub clear_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" Text7.Text = "" End Sub Private Sub exit_Click() End End Sub Private Sub result_Click() Dim t1 As Boolean t1 = True s1 = Val(Text1.Text) s2 = Val(Text2.Text) s3 = Val(Text3.Text) s4 = Val(Text4.Text) s5 = Val(Text5.Text) s6 = Val(Text6.Text) Avg = (s1 + s2 + s3 + s4 + s5 + s6) / 6 Select Case t1 Case s1 < 40 Or s2 < 40 Or s3 < 40 Or s4 < 40 Or s5 < 40 Or s6 < 40 Text7.Text = "Failed" Case Avg < 60 Text7.Text = "Second Class" Case Else Text7.Text = "First Class" End Select End Sub

Program No 5 : Program using scientific calculator Private Sub cmdsin_Click( ) Dim s As Double s = Sin(Val(Text1.Text) * 3.142 / 180) Text2.Text = s End Sub Private Sub cmdcos_Click( ) Dim c As Double c = Cos(Val(Text1.Text) *3.142 / 180) Text2.Text = c End Sub Private Sub cmdtan_Click( ) Dim t As Double t = Tan (Val(Text1.Text) * 3.142/ 180 Text2.Text = t End Sub Private Sub cmdlog_Click( ) Dim I As Double I = Log(Val(Text1.Text)) / 2.303 Text2.Text = I End Sub Private Sub cmdreciprocal_Click( ) Dim r As Double r = 1/(Val(Text1.Text)) Text2.Text = r End Sub Private Sub cmdsqroot_Click( ) Dim sq As Double sq = Sqr(Val(Text1.Text)) Text2.Text = sq

End Sub Private Sub cmdsq_Click( ) Dim squa As Double squa = Val(Text1.Text) * Val(Text1.Text) Text2.Text = squa End Sub Private Sub cmdclear_Click( ) Text1.Text = “” Text2.Text = “” End Sub Private Sub cmdexit_Click( ) Dim S1, S2 As String S1 = MsgBox(“DO U WANT TO EXIT”, vbYesNo) If S1 = vbYes Then S2 = MsgBox(“THANKS”)

Unload Me End If End Sub

Program No 6 : Program to create Graphic Editor Private Sub big_Click() Shape1.height = 2500 Shape1.Width = 2500 End Sub Private Sub blue_Click() Shape1.FillColor = vbBlue End Sub Private Sub green_Click() Shape1.FillColor = vbGreen End Sub Private Sub medium_Click() Shape1.height = 2000 Shape1.Width = 2000 End Sub Private Sub red_Click() Shape1.FillColor = vbRed End Sub Private Sub small_Click() Shape1.height = 1500 Shape1.Width = 1500 End Sub Private Sub thick_Click() Shape1.BorderWidth = 5 End Sub

Private Sub thicker_Click() Shape1.BorderWidth = 10 End Sub Private Sub thin_Click() Shape1.BorderWidth = 1 End Sub

Program No 7 : Program to calculate sum of 100 numbers Dim i, a, s As Integer Private Sub add_Click() i = 0 a = 0 s = 0 Do While i <= 100 a = InputBox("Please enter 100 numbers to be added") s = s + a i = i + 1 Loop End Sub Private Sub clear_Click() Text1.Text = "" End Sub Private Sub exit_Click() End End Sub Private Sub result_Click() Text1.Text = s End Sub

Program No 8 : Validate Name, Date of Birth and Telephone number

Private Sub clear_Click() name1.Text = "" dob.Text = "" tele.Text = "" End Sub Private Sub exit_Click() End End Sub Private Sub valid_Click() Dim a, L As Integer a = 0 L = Len(name1.Text) If L = 0 Then MsgBox ("Name cannot be Blank") a = 1 Else For i = 1 To L ch = UCase(Mid(name1.Text, i, 1)) If Not ((ch >= "A" And ch <= "Z") Or (ch = "")) Then MsgBox ("Invalid Name") name1.Text = "" name1.SetFocus a = 1 i = L + 1 End If Next End If If IsDate(dob.Text) <> True Then MsgBox ("Enter a valid Date of Birth") dob.Text = "" dob.SetFocus a = 1

End If If IsNumeric(tele.Text) <> True Then MsgBox ("Enter valid Telephone number") tele.Text = "" tele.SetFocus a = 1 End If If a = 0 Then MsgBox ("All fields are valid") MsgBox ("Thank you") End If End Sub

C++

Program No 1 : Calculate area and circumference of circle using class #include<iostream.h> #include<conio.h> class circle { private: float r,a,c,x,y; public: circle() { r=7; x=6; y=8; } void area() { a=3.14*r*r; } void circum() { c=2*3.14*r; } void print() { cout<<"The radius of the circle is"<<r; cout<<"\n\nThe x,y coordinate of center is"<<x<<","<<y; cout<<"\n\nThe area of circle is="<<a; cout<<"\n\nThe circumference of circle is"<<c; } }; void main() { clrscr(); circle c; c.area(); c.circum(); c.print(); } Output The radius of the circle is 7 The x,y, coordinate of center is 6,8 The area of circle is 153.860001 The circumference of circle is 43.959999

Program No 2 : Search a number using binary search #include<iostream.h> #include<conio.h> int bsearch(int[],int); void main() { int a[10],i,d,loc; clrscr(); cout<<"enter any 10 numbers in ascending order"; for(i=0;i<10;i++) { cin>>a[i]; } cout<<"enter the number to be searched"; cin>>d; loc=bsearch(a,d); if(loc) cout<<"\nNumber found at location:"<<loc; else cout<<"\nNumber not found"; getch(); } int bsearch(int y[],int dt) { int mid,lb,ub; lb=0; ub=10-1; while(ub>=lb) { mid=(ub+lb)/2; if(y[mid]==dt) return mid+1; if(y[mid<dt) lb=mid+1; else ub=mid-1;

} return 0; } Output Enter any 10 numbers 1 3 4 5 6 8 9 12 14 15 Enter to be searched 8 Number found at location 6 Enter any 10 numbers 1 3 4 5 6 8 9 12 14 15 Enter to be searched 18 Number not found

Program No 3 : Sort numbers using Bubble Sort #include<iostream.h> #include<conio.h> void main() { int a[10],i,j,temp; cout<<"Enter the elements of the array\n"; for(i=0;i<10;i++) { cin>>a[i]; } cout<<"Original array is"; for(i=0;i<10;i++) { cout<<a[i]; } for(i=0;i<10;i++) { for(j=0;j<10-i;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } cout<<"After Bubble sort Ascending order is\n"; for(i=0;i<10;i++) { cout<<a[i]; } getch(); }

//Output Enter the elements of the array 10 9 8 7 6 5 4 3 2 1 Original Array is 10 9 8 7 6 5 4 3 2 1 After Bubble sort Ascending order is 1 2 3 4 5 6 7 8 9 10

Program No 4 : Program using class inheritance #include<iostream.h> #include<conio.h> class student { protected: int rollno; public: void setno(int a) { roll no=a; } void dispro() { cout<<"Roll no="<<rollno<<endl; } }; class test: public student { protected: float marks1,marks2; public: void setmarks(float x,float y) { marks1=x; marks2=y; } void dismarks() { cout<<"Marks obtained in 1st test="<<marks1<<endl; cout<<"Marks obtained in 2nd test="<<marks2<<endl; } }; class sports { protected: float score; public: void setscore(float x) { score=x;

} void dispscore() { cout<<"\nScore in sports="<<score<<endl; } }; class result: public test, public sports { float total; public: void display() { total=marks1+marks2+score; dispro(); dispmarks(); dispscore(); cout<<"Total marks"<<total<<endl; } }; void main() { clrscr(); result s1; s1.setno(100); s1.setmarks(20,20); s1.setscore(10); s1.display(); getch(); }

Program No 5 : Program using Constructor and Destructor #include<iostream.h> #include<conio.h> class ratio { public: ratio() { cout<<"\n\nThe Object is born"; } void f1() { cout<<"\n\nNow object is alive"; } ~ratio() { cout<<"\n\nObject dies"; } }; void main() { clrscr(); ratio r; r.f1(); getch(); } Output The object is Born Now object is alive Object dies

Program No 6 : Program polar-rectangle & rectangle-polar conversion #include<iostream.h> #include<conio.h> #include<math.h> class rectangle { float x,y; public:void getdata1() { cout<<"Enter the rectangular coordinates"; cout<<"\nx="; cin>>x; cout<<"\ny="; cin>>y; } void con_rec_pol() { float r,t; r=sqrt(x*x+y*y); t=atan(y/x)*180/3.14; cout<<"\nRectangle to polar conversion is"; cout<<"\n r="<<r; cout<<"\n theta="<<t; } }; class polar { float r,t; public:void getdata2() { cout<<"\n\nEnter the polar coordinates"; cout<<"\nr="; cin>>r; cout<<"\ntheta="; cin>>t;

} void conv_pol_rec() { float x,y; x=r*cos(t*3.14/180); y=r*sin(t*3.14/180); cout<<"\n\nPolar to Rectangle conversion is"; cout<<"\n x="<<x; cout<<"\n y="<<y; } }; void main() { clrscr(); rectangle rect1; rect1.getdata1(); rect1.con_rec_pol(); polar pol1; pol1.getdata2(); pol1.conv_pol_rec(); getch(); } Output Enter the rectangular coordinates x=2 y=3 Rectangle to polar conversion is r=3.605551 theta=56.338493 Enter the polar coordinates r=3.605551 theta=56.338493 Polar to rectangle conversion is x=2 y=3

Program No 7 : Program with a Ratio class using Member Function #include<iostream.h> #include<conio.h> class ratio { int num,den; public:void assign(); double convert(); void invert(); void print(); }; void ratio::assign() { cout<<"Enter numerator"<<endl; cin>>num; cout<<"Enter denominator"<<endl; cin>>den; } double ratio::convert() { return (num/den); } void ratio::invert() { int temp; temp=num; num=den; den=temp; } void ratio::print() { cout<<num<<"/"<<den<<endl; } void main() { clrscr();

ratio r; r.assign(); cout<<"Original ratio is="; r.print(); cout<<"Inverse ratio is="; r.convert(); r.invert(); r.print(); getch(); } Output Enter Numerator 2 Enter Denominator 3 Original Value is = 2/3 Inverse Value is = 3/2

Program No 8 : Program using virtual function #include<string.h> #include<iostream.h> #include<conio.h> class Person { private: char name[80]; public: Person() { strcpy(name,"BOB"); } virtual void print() { cout<<"\nName of the person assigned through base object is"<<name; } }; class student:public Person { private: char name1[80]; public: student() { strcpy(name1,"TOM"); } void print() { cout<<"\nName of the person assigned through derived object"<<name1; } }; void main() { clrscr(); Person *p,x; student y; p=&x; p->print();

p=&y; p->print(); getch(); } // Output Name of the person assigned through base object is BOB Name of the person assigned through derived object is TOM

HTML Program No 1 : Design a HTML Page for College Home.html <html><head> <title> College profile</title></head> <body bgcolor="green"> <marquee behavior=alternate><h1 align="center"><font color=red> PACE Junior Science College</font></h1> </center></marquee><br> <p><font face="Century" color="white"> Four years ago, IIT-ian's Pace introduced the unique concept of integrated learning for Competitive Exams, Board Exams through partnerships with the most reputed schools and colleges across Mumbai.</p><br><br> <p>In 2009, the Government of Maharashtra entrusted IIT-ian's Pace with the responsibility to manage two Junior Science colleges in collaboration with the MCGM. These colleges offer integrated Competitive Exam preparation and Board preparation under one roof.</p><br><br> <p>Today, the success of this concept has led to a revolution for competitive exams and boards. In a landmark ruling, <u>the Government of Maharashtra awarded IIT-ian's Pace</u> special permission to run 6 Pace Junior Science colleges across Mumbai.</font> <br><br> <h3><a href="courses.html">Courses</a><br> <a href="admission.html">Admission process</a><br> <img src="pace.jpg"></img > </body> </html>

Admission.html <html><head><title>Admission</title></head> <body> <marquee><font color=red><h2>6 Pace Junior Science Colleges (Andheri, Borivali, Dadar, Nerul, Powai, Thane)</h2></font></marquee><br><br> <b><u>Eligibility Criteria</u>:</b> Direct admission to the students scoring 90% and above in PCM in X Boards or IX Final exams. Aptitude test is compulsory for other students.<br> <br><br> <b><u>Admission Form</u>:</b> To be collected from the respective Pace Junior Science Colleges/ centers <br><br> <b><u>Documents required</u>:</b><br> <ol type="A"> <li>X standard mark sheet (original with attested copy)</li> <li>School Leaving Certificate</li> <li>5 passport size photographs</li> </ol> <br><h3><a href="courses.html">Courses</a><br> <a href="home.html">Home</a> </body> </html> Courses.html <html><head> <title> Courses offered</title></head> <body bgcolor=green><font color=black> <marquee><h2>Courses available at PACE Junior Science College</h2></marquee></font> <font size=5 color=white><pre> <ol> <li> XI and XII IITJEE / AIEEE </li> <li> XI and XII MH-CET </li> <li> XI and XII </li>

</ol></pre></font> <u><i><h3> <font color=black>Vocational subjects offered at Pace Junior Science College</font> </h3></i></u> <font size=4 color=white><ul> <li>Electrical Maintenance </li> <li> Computer Science </li> </ul></font> <br><h3><a href="admission.html">Admission</a><br> <a href="home.html">Home</a> </body> </html>

Program No 2 : Design a HTML Page to draw Table Table1.html

<html><head><title>table</title></head> <body bgcolor="brown"> <font face="Arial Rounded MT Bold" size="2" color="yellow"> <marquee>Record</marquee> <table border=1 align=center> <caption>College cut offs</caption> <tr> <th align="center">Year</th> <th align="center">Stream</th> <th align="center">Cut off (%)</th> </tr> <tr> <th rowspan="2">FYJC</th> <td align="center">Commerce</th> <td align="center"> 75 </th> </tr> <tr> <td align="center">Science</td> <td align="center">90</td> </tr> <tr> <th align="center">FYBCom</th> <td align="center">IT</td> <td align="center"> 70 </td> </tr> <tr> <th rowspan="2">FYBSc</th> <td align="center">IT</td> <td align="center"> 80 </td> </tr> <tr> <td align="center">CS</td>

<td align="center">85</td> </tr> </table> <p><a href="home.html"><img src="Sunset.jpg" height=200 width=250></img></a></p> </font> </body> </html>

Paper II : Hardware

Programs for 8085 Microprocessor

Q 1) A Block of data is stored in memory location starting from C040. Length of the block is stored in register D. Write a program to transfer the entire block of data to another memory location starting from memory location C050

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 LXI B, C050H ;Initialize the register pair BC to memory location C050

H C004 50

C005 C0

C006 MVI D, 05 H ;Set the counter for 05 numbers in register D C007 05

C008 :UP MOV A,M ;Copy the data content of HL pair to accumulator

C009 STAX B ;Store the data content of accumulator to register pair

BC C00A INX H ;Increment the memory

location of HL register pair by 1

C00B INX B ;Increment the memory location of BC register pair

by 1 C00C DCR D ;Decrement the counter by 1

C00D JNZ UP: ;If counter 0 (reg.D0)then jump to memory

location c008 C00E 08

C00F C0

C010 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C041 = 02 H C042 = 03 H C043 = 04 H C044 = 05 H

After Execution :

A =

D =

F =

C050 = C051 = C052 = C053 = C054 =

F =

S Z X AC X P X CY

Q2) A Block of data is stored in memory location starting from C040. Length of the block is stored in register D. Write a program to transfer the entire block of data to another memory location starting from memory location C050 in reverse order.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 LXI B, C054H ;Initialize the register pair BC to memory location C054

H C004 54

C005 C0

C006 MVI D, 05 H ;Set the counter for 05 numbers in register D C007 05

C008 :UP MOV A,M ;Copy the data content of HL pair to accumulator

C009 STAX B ;Store the data content of accumulator to register pair

BC C00A INX H ;Increment the memory

location of HL register pair by 1

C00B DCX B ;Increment the memory location of BC register pair

by 1 C00C DCR D ;Decrement the counter by 1

C00D JNZ UP: ;If counter 0 (reg.D0)then jump to memory

location c008 C00E 08

C00F C0

C010 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C041 = 02 H C042 = 03 H C043 = 04 H C044 = 05 H

After Execution :

A =

D =

F =

C050 = C051 = C052 = C053 = C054 =

F =

S Z X AC X P X CY

Q3)A block of data is stored in memory location starting from memory location C040 . Another block of data is stored in memory location starting from memory location C050. Length of the blocks is stored in register D. Write a program to exchange / swap the data contents of both these blocks

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 LXI B, C050H ;Initialize the register pair BC to memory location C050

H C004 50

C005 C0

C006 MVI D, 05 H ;Set the counter for 05 numbers in register D C007 05

C008 : UP

LDAX B

;Load the data contents of register pair BC to

accumulator C009 MOV E , A ;Copy the data content of

accumulator to register E C00A MOV A ,M ;Copy the data content of

register pair HL to accumulator

C00B STAX B ;Store the data content of accumulator to register pair

BC C00C MOV M , E ;Copy the data content of

register E to register pair HL C00D INX H ;Increment the memory

location of HL register pair by 1

C00E INX B ;Increment the memory location of BC register pair

by 1 C00F DCR D ;Decrement the counter by 1

C010 JNZ UP: ;If counter 0 (reg D 0 )then jump to memory

location c008 C011 08 C012 C0 C013 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C050 =

06H

C041 = 02 H C051 =

07H

C042 = 03 H C052 =

08H

C043 = 04 H C053 =

09H

C044 = 05 H C054 =

0AH

After Execution :

A =

D =

F =

C040 = C050 =

C041 = C051 =

C042 = C052 =

C043 = C053 =

C044 = C054 =

F

S Z X AC X P X CY

Q 4) A block of data is stored in memory location starting from C040 . Length of the block is stored in register B. Write a program to add the data content of the memory location and store the result at the end of the block.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 XRA A ;Clear the data content of accumulator

C001 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C002 40

C003 C0

C004 MVI B, 05 H ;Set the counter for 05 numbers in register B C005 05

C006 :UP ADD M ;Add the data content of register pair HL to

accumulator C007 INX H ;Increment the memory

location of HL register pair by 1

C008 DCR B ;Decrement the counter by

C009 JNZ UP: ;If counter 0 (reg B 0 )then jump to memory

location C005 C00A 06

C00B C0

C00C MOV M ,A ;Copy the data content of accumulator to register pair

HL C00D RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C041 = 02 H C042 = 03 H C043 = 04 H C044 = 05 H

After Execution :

A =

B=

F =

C045 =

F

S Z X AC X P X CY

Q 5) A block of data is stored in memory location starting from C041 . Length of the block is stored in memory location C040. Write a program to add the data content of the memory location and store the result at the end of the block.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 XRA A ;Clear the data content of accumulator

C001 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C002 40

C003 C0

C004 MOV B , M ;Copy the counter stored at memory location to register

B C005 INX H ;Increment the memory

location of HL register pair by 1

C006 :UP ADD M ;Add the data content of register pair HL to

accumulator C007 INX H ;Increment the memory

location of HL register pair by 1

C008 DCR B ;Decrement the counter by 1

C009 JNZ UP: ;If counter 0(reg B 0 ) then jump to memory

location C005 C00A 06

C00B C0

C00C MOV M ,A ;Copy the data content of accumulator to register pair

HL C00D RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 05H C041 = 01 H C042 = 02 H C043 = 03 H C044 = 04 H C045 05 H

After Execution :

A =

B=

F =

C046 =

F

S Z X AC X P X CY

Q 6) A block of data is stored in memory location starting from C040 . Length of the block is stored in register B. Write a program to find the largest number from the given block of data and store it at the end of the block.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040 H C001 40

C002 C0

C003 MVI A, 00 H ;Assign the lowest value of data to accumulator C004 00

C005 MVI B, 05 H ;Set the counter for 05 numbers in register B C006 05

C007 : UP CMP M ;Compare the data content of register pair HL with the

data content of accumulator C008 JNC NEXT : ;If carry flag is not set then

jump to memory location C00C C009 0C

C00A C0

C00B MOV A , M ;Copy the data content of register pair HL th

accumulator C00C :

NEXT INX H ;Increment the memory

location of HL register pair by 1

C00D DCR B ;Decrement the counter by 1

C00E JNZ UP : ;If counter 0 (reg B 0 )then jump to memory

location C007 C00F 07

C010 C0

C011 MOV M , A ;Store the largest number at the end of block

C012 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C041 = 02 H C042 = 0A H C043 = 04 H C044 = 05 H

After Execution :

A =

B=

F =

C045 =

F

S Z X AC X P X CY

Q 7) A block of data is stored in memory location starting from C040 . Length of the block is stored in register B. Write a program to find the smallest number from the given block of data and store it at the end of the block.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040 H C001 40

C002 C0

C003 MVI A, FF H ;Assign the highest value of data to accumulator C004 FF

C005 MVI B, 05 H ;Set the counter for 05 numbers in register B C006 05

C007 : UP CMP M ;Compare the data content of register pair HL with the

data content of accumulator C008 JC NEXT : ;If carry flag is set then jump

to memory location C00C C009 0C

C00A C0

C00B MOV A , M ;Copy the data content of register pair HL th

accumulator C00C :

NEXT INX H ;Increment the memory

location of HL register pair by 1

C00D DCR B ;Decrement the counter by 1

C00E JNZ UP : ;If counter 0 (reg B 0 )then jump to memory

location C007 C00F 07

C010 C0

C011 MOV M , A ;Store the smallest number at the end of block

C012 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 06 H C041 = 07 H C042 = 0A H C043 = 08 H C044 = 01 H

After Execution :

A =

B=

F =

C045 =

F

S Z X AC X P X CY

Q 8) A block of data is stored in memory location starting from C040. Length of the block is stored in register B. Write a program to find the first occurrence of the number AB H from the given block of data and if the number is not found store FFFF H in HL - pair

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040 H C001 40

C002 C0

C003 MVI A, AB H ;Load the data AB H to accumulator C004 AB

C005 MVI B, 05 H ;Set the counter for 05 numbers in register B C006 05

C007 : UP CMP M ;Compare the data content of register pair HL with the

data content of accumulator C008 JZ NEXT : ;If Zero flag is set then jump

to memory location C013 C009 13

C00A C0

C00B INX H ;Increment the memory location of HL register pair

by 1 C00C DCR B ;Decrement the counter by 1

C00D JNZ UP : ;If counter 0 (reg B 0 )then jump to memory

location C007 C00E 07

C00F C0

C010 LXI H, FFFF H ;Initialize the register pair HL to memory location FFFF H C011 FF

C012 FF

C013 :NEXT RST 1 ;Stop the execution

OUTPUT :

Case I:

Before Execution :

C040 = 01 H C041 = 02 H C042 = AB H C043 = 04 H C044 = AB H After Execution :

A =

B=

H =

L =

F =

F =

Case II: Before Execution :

C040 = 01 H C041 = 02 H C042 = 03 H C043 = 04 H C044 = 05 H After Execution :

A =

B=

H =

L =

F =

F =

S Z X AC X P X CY

S Z X AC X P X CY

Q 9) A block of data is stored in memory location starting from C040. Length of the block is stored in register B. Write a program to find the number of times the data AB H occurred from the given block of data and store the result at the end of the block

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040 H C001 40

C002 C0

C003 MVI A, AB H ;Load the data AB H to accumulator C004 AB

C005 MVI B, 05 H ;Set the counter for 05 numbers in register B C006 05

C007 MVI C , 00 H ;Clear the data content of register C C008 00

C009 : UP CMP M ;Compare the data content of register pair HL with the

data content of accumulator C00A JNZ NEXT : ;If Zero flag is set then jump

to memory location C013 C00B 0E

C00C C0

C00D INR C ;Increment the data content of register C by 1

C00E :NEXT INX H ;Increment the memory location of HL register pair

by 1 C00F DCR B ;Decrement the counter by 1

C010 JNZ UP : ;If counter 0 (reg B 0 )then jump to memory

location C006 C011 09

C012 C0

C013 MOV M , C ;Copy the data content of register C to register pair HL

C014 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = AB H C041 = 02 H C042 = AB H C043 = 04 H C044 = AB H

After Execution :

A =

B=

C =

C045 =

F =

S Z X AC X P X CY

Q 10) A block of data is stored in memory location starting from C040. Length of the block is stored in register B. Write a program to find the total number of odd and even numbers from the given block of data and stored it at the end of block

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040 H C001 40

C002 C0

C003 MVI B, 05 H ;Set the counter for 05 numbers in register B C004 05

C005 MVI D, 00 H ;Clear the data content of register D C006 00

C007 MVI E , 00 H ;Clear the data content of register E C008 00

C009 : up MOV A , M ;Copy the data content of register pair HL to

accumulator C00A RRC ;Rotate the data content of

accumulator 1-bit position to the right L.S.B. will shift in carry as well as in M.S.B.

C00B JC NEXT : ;If carry flag is set then jump to memory location C012 C00C 12

C00D C0 C00E INR C ;Increment the data content

of register C by 1 C00F JMP DOWN : ;Jump to memory location

C013 C010 13 C011 C0 C012 : NEXT INR D ;Increment the data content

of register C by 1 C013 : DOWN INX H ;Increment the memory

location of HL register pair by 1

C014 DCR B ;Decrement the counter by 1

C015 JNZ UP : ;If counter 0 (reg B 0 )then jump to memory

location C009

Memory Location

Op-Code

Labels Mnemonics Comments

C016 09

C017 C0

C018 MOV M , D ;Store the number of odd numbers in the next memory

location of register pair HL C019 INX H ;Increment the memory

location of HL register pair by 1

C01A MOV M , E ;Store the number of even numbers in the next memory

location of register pair HL C01B RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 01 H C041 = 02 H C042 = 03 H C043 = 04 H C044 = 05 H

After Execution :

A =

B=

D =

E=

F =

C045 =

C046 =

F = S Z X AC X P X CY

Q 11) Two numbers are stored in consecutive memory location starting from C040. Write a program to multiply the numbers and store the result in the next memory location.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 XRA A ;Clear the data content of accumulator

C001 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C002 40

C003 C0

C004 MOV B , M ;Copy the counter stored at memory location to register

B C005 INX H ;Increment the memory

location of HL register pair by 1

C006 :UP ADD M ;Add the data content of register pair HL to

accumulator C007 DCR B ;Decrement the counter by 1

C008 JNZ UP: ;If counter 0(reg B 0 ) then jump to memory

location C006 C009 06

C00A C0

C00B INX H ;Increment the memory location of HL register pair

by 1 C00C MOV M ,A ;Copy the data content of

accumulator to register pair HL

C00D RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 03 H C041 = 04 H After Execution :

A =

B=

F =

C042 =

F =

S Z X AC X P X CY

Q 12) An one byte number is stored in memory location starting from C030. Write a program to separate the two nibbles of the one byte number and store them in the next memory location. Also write a program to multiply the separated nibbles and store the result at the end of the block

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C030H ;Initialize the register pair HL to memory location C030 H C001 30

C002 C0

C003 MOV A , M ;Copy the data content of register pair HL to

accumulator C004 ANI , 0F H ;AND immediately the data

0F H with the data content of accumulator C005 0F

C006 MOV B , A ;Store the separated lower order nibble to register B

C007 INX H ;Increment the memory location of HL register pair

by 1 C008 MOV M ,A ;Store the separated nibble

to register pair HL C009 DCX H ;Decrement the memory

location of HL register pair by 1

C00A MOV A , M ;Copy the data content of register pair HL to

accumulator C00B ANI , F0 H ;AND immediately the data

F0 H with the data content of accumulator C00C F0

C00D RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C00E RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C00F RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C010 RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C011 INX H ;Increment the memory location of HL register pair

by 1 C012 INX H ;Increment the memory

location of HL register pair by 1

C013 MOV M , A ;Store the separated nibble to register pair HL

C014 XRA A ;Clear the data content of accumulator

C015 :UP ADD M ;Add the data content of register pair HL to

accumulator C016 DCR B ;Decrement the data content

of register B by 1 C017 JNZ UP : ;If counter 0(reg B 0 )

then jump to memory location C015 C018 15

C019 C0

C01A INX H ;Increment the memory location of HL register pair

by 1 C01B MOV M ,A ;Store the result of

multiplication of the separated nibble at the end of

block C01C RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C030 = 32 H

After Execution :

A =

B=

F =

C031 =

C032 =

C033 =

F =

S Z X AC X P X CY

Q 13) Two numbers are stored in consecutive memory location starting from C040. Write a program to subtract the numbers and store the absolute difference result in the next memory location.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 MOV A , M ;Copy the data content of register pair HL to

accumulator C004 INX H ;Increment the memory

location of HL register pair by 1

C005 SUB M ;Subtract the data content of register pair HL with the

data content of accumulator C006 JP DOWN : ;If the result in accumulator

is positive then jump to memory location C00B C007 0B

C008 C0

C009 CMA ;Compliment the data content of accumulator

C00A INR A ;Increment the data content of accumulator by 1

C00B : DOWN

INX H ;Increment the memory location of HL register pair

by 1 C00C MOV M ,A ;Copy the data content of

accumulator to register pair HL

C00D RST 1 ;Stop the execution

OUTPUT :

Case I :

Before Execution :

C040 = 09 H C041 = 04 H

After Execution :

A =

F =

C042 =

F

Case II :

Before Execution :

C040 = 04 H C041 = 09 H

After Execution :

A =

F =

C042 =

F

S Z X AC X P X CY

S Z X AC X P X CY

Q 14)Two numbers are stored in memory location starting from C040 . Write a program to divide the two numbers and store the quotient and remainder in the next consecutive memory locations.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 MVI C , 00H ;Clear the data content of register C C004 00

C005 MOV A , M ;Copy the data content of register pair HL to

accumulator C006 INX H ;Increment the memory

location of HL register pair by 1

C007 :UP CMP M ;Compare the data content of HL pair with the data

content of accumulator C008 JC DOWN : ;If carry flag is set then jump

to memory location C010 C009 10

C00A C0

C00B SUB M ;Subtract the data content of register pair HL from data

content of accumulator C00C INR C ;Increment the data content

of register C by 1 C00D JMP UP: ;Jump to memory location

C007 C00E 07

C00F C0

C010 :DOWN INX H ;Increment the memory location of HL register pair

by 1 C011 MOV M , C ;Store the quotient in the

next memory location C012 INX H ;Increment the memory

location of HL register pair by 1

C013 MOV M , A ;Store the remainder in the next memory location

C014 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 09 H C041 = 02 H

After Execution :

A =

C =

F =

C042 =

C043 =

F

S Z X AC X P X CY

Q 15)A 4-byte number is stored in memory location starting from C040. Write a program to find whether the given 4-bybe number is a palindrome or not . If it is a palindrome then store 00 H in memory location C060 and if it is not a palindrome then store FF H in memory location C060. For eg. Take the 4-byte number as AB5005BA H

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 LXI D, C043H ;Initialize the register pair DE to memory location C043

H C004 43

C005 C0

C006 MVI B , 02H ;Set the counter for 2 numbers in register B C007 02

C008 : UP LDAX D ;Load the data contents of register pair DE to

accumulator C009 RRC ;Rotate the data bit of

accumulator one bit position to right L.S.B will shift in carry as well as in M.S.B

C00A RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C00B RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C00C RRC ;Rotate the data bit of accumulator one bit position

to right L.S.B will shift in carry as well as in M.S.B

C00D CMP M ;Compare the data content of register pair HL with data

content of accumulator C00E JZ NEXT: ;If zero flag is set then jump

C00F 19 to memory location C019

C010 C0

C011 MVI A , FF H ;Load data FF H immediately to accumulator C012 FF

C013 STA C060 H ;Store the data contents of accumulator to memory

location C060 C014 60

C015 C0

C016 JMP END : ;Jump to memory location C024 C017 24

C018 C0

C019 :NEXT INX H ;Increment the memory location of HL register pair

by 1 C01A DCX D ;Decrement the memory

location of DE register pair by 1

C01B DCR B ;Decrement the data content of register B by 1

C01C JNZ UP : ;If counter 0(reg B 0 ) then jump to memory

location C008 C01D 08

C01E C0

C01F MVI A , 00 H ;Load data FF H immediately to accumulator C020 00

C021 STA C060 H ;Store the data contents of accumulator to memory

location C060 C022 60

C023 C0

C024 :END RST 1 ;Stop the execution

OUTPUT :

Case I

Before Execution :

C040 = AB H C041 = 50 H C042 = 05 H C043 = BA H

After Execution :

A =

B=

F =

C060 =

F

Case II

Before Execution :

C040 = AB H C041 = 50 H C042 = 55 H C043 = BA H

After Execution :

A =

B=

F =

C060 =

F

S Z X AC X P X CY

S Z X AC X P X CY

Q 16) A 2-byte number is stored in memory location starting from C040 beginning with lower order byte byte. Another 2- byte number is stored in memory location starting from C050 beginning with lower order byte. Write a program to add these two numbers and store the result in memory location starting from C060 beginning with lower order byte.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H C001 40

C002 C0

C003 LXI B, C050H ;Initialize the register pair HL to memory location C050

H C004 50 C005 C0 C006 LDAX B ;Load the data contents of

register pair BC to accumulator

C007 ADD M ;Add the data contents of register pair HL to

accumulator C008 STA C060 ;Store the data contents of

accumulator (Lower order byte)to memory location

C060

C009 60

C00A CO C00B INX H ;Increment the memory

location of HL register pair by 1

C00C INX B ;Increment the memory location of BC register pair

by 1 C00D LDAX B ;Load the data contents of

register pair BC to accumulator

C00E ADC M ;Add the data contents of register pair HL along with

carry to accumulator C00F STA C061 ;Store the data contents of

accumulator (Higher order byte)to memory location

C061

C010 61

C011 C0 C012 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C050 = C2 H C051 = FE H

After Execution :

A =

F =

F =

C040 = C9 H C041 = AB H

C060 = C061 =

S Z X AC X P X CY

Q 17) A 4-byte number is stored in memory location starting from C040 beginning with lower order byte byte. Another 4- byte number is stored in memory location starting from C050 beginning with lower order byte. Write a program to add these two 4- byte numbers and store the result in memory location starting from C040 beginning with lower order byte.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 XRA A ;Clear the data content of accumulator

C001 LXI H, C040H ;Initialize the register pair HL to memory location C040

H

C002 40

C003 C0

C004 LXI B, C050H ;Initialize the register pair BC to memory location C050 H C005 50

C006 C0 C007 MVI D , 04 H ;Set the counter of 4

numbers to register D C008 04

C009 :UP LDAX B ;Load the data contents of register pair BC to

accumulator C00A ADC M ;Add the data contents of

register pair HL along with carry to accumulator

C00B MOV M , A ;Copy the data contents of accumulator to register pair

HL C00C INX H ;Increment the memory

location of HL register pair by 1

C00D INX B ;Increment the memory location of BC register pair

by 1 C00E DCR D ;Decrement the data content

of register B by 1 C00F JNZ UP: ;If counter 0(reg D 0 )

then jump to memory location C009 C010 09

C011 C0 C012 RST 1 ;Stop the execution

OUTPUT :

Before Execution :

After Execution :

A =

D =

F =

F =

C040 = C9 H C041 = AB H C042 = FD H C043 = FE H

C050 = C2 H C051 = FF H C052 = C9 H C053 = FF H

C040 = C041 = C042 = C043 =

S Z X AC X P X CY

Q 18) A block of data is stored in memory location starting from C041. Length of data is stored in memory location C040. Write a program to add this numbers by using DAD instruction. Store the two byte result at the end of the block

Memory Location

Op-Code

Labels Mnemonics Comments

C000 LXI H, C040H ;Initialize the register pair HL to memory location C040

H

C001 40

C002 C0

C003 LXI B, 0000H ;Initialize the register pair BC to

0000 H

C004 00

C005 00

C006 LXI D, 0000H ;Initialize the register pair DE to

0000 H

C007 00

C008 00

C009 MOV A ,M ;Copy the data contents of register pair HL to

accumulator . C00A : UP INX H ;Increment the memory

location of HL register pair by 1

C00B MOV C ,M ;Copy the data contents of register pair HL to register C

. C00C XCHG ;The content of register H are

exchanged with that of register D and the content of

register L are exchanged with that of register E

C00D DAD B ;The content of register pair BC are added to the contents of Hl pair. Result is placed in

register H and L C00E XCHG ;The content of register H are

exchanged with that of

register D and the content of register L are exchanged

with that of register E C00F DCR A ;Decrement the data content

of register A by 1 C010 JNZ UP : ;If counter 0(reg A 0 )

then jump to memory location C00B C011 0B

C012 C0

C013 INX H ;Increment the memory location of HL register pair

by 1 C014 MOV M , E ;Copy the data contents of

register E to register pair HL C015 INX H ;Increment the memory

location of HL register pair by 1

C016 MOV M , D ;Copy the data contents of register Dto register pair HL

C017 RST 1 ;Stop the execution

OUTPUT :

Case I : Before Execution :

C040 = 05 H C041 = C9 H C042 = AB H C043 = FD H C044 = FE H C045 = C9 H After Execution :

A =

F =

C046 =

C047 =

F= S Z X AC X P X CY

Q 19) A block of data is stored in memory location starting from C041. Length of data is stored in memory location C040. Write a program to sort the content of the block in ascending order.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 :START MVI B ,00 H Set the data content of register to 00H C001 00

C002 LXI H, C040H ;Initialize the register pair HL to memory location C040

H

C003 40

C004 C0

C005 MOV C, M ;Copy the data contents of register pair HL to register C

. C006 INX H ;Increment the memory

location of HL register pair by 1

C007 MOV A , M ;Copy the data contents of register pair HL to

accumulator . C008 DCR C ;Decrement the data content

of register C by 1 (Decrement the counter by

1) C009 : UP INX H ;Increment the memory

location of HL register pair by 1

C00A CMP M ;Compare the data content of register pair HL with data

content of accumulator C00B JC DOWN : If Carry flag = 1then jump to

memory location C015. C00C 15

C00D C0

C00E MOV D , M ; Copy the data contents of register pair HL to register D

. C00F MOV M , A ; Copy the data contents of

register pair HL to accumulator .

C010 DCX H ;Decrement the memory

location of HL register pair by 1

C011 MOV M , D ;Copy the data contents of register D to register pair HL

C012 INX H ;Increment the memory location of HL register pair

by 1 C013 MVI B, 01 H

C014 01

C015 : DOWN

DCR C ;Decrement the data content of register C by 1

(Decrement the counter by 1)

C016 JNZ UP : ;If counter 0(reg C 0 ) then jump to memory

location C009 C017 09

C018 C0

C019 DCR B ;Decrement the data content of register B by 1

C01A JZ START : If Zero flag = 1 then jump to memory location C000 C01B 00

C01C C0

C01D RST 1 ;Stop the execution

OUTPUT :

Before Execution :

C040 = 05 H C041 = 04 H C042 = 03 H C043 = 02 H C044 = 05 H C045 = 01 H

After Execution :

A =

B =

F =

C041 = C042 = C043 = C044 = C045 =

F=

S Z X AC X P X CY

Q 20) A block of data is stored in memory location starting from C041. Length of data is stored in memory location C040. Write a program to sort the content of the block in descending order.

Memory Location

Op-Code

Labels Mnemonics Comments

C000 :START MVI B ,00 H Set the data content of register to 00H C001 00

C002 LXI H, C040H ;Initialize the register pair HL to memory location C040

H

C003 40

C004 C0

C005 MOV C, M ;Copy the data contents of register pair HL to register C

. C006 INX H ;Increment the memory

location of HL register pair by 1

C007 MOV A , M ;Copy the data contents of register pair HL to

accumulator . C008 DCR C ;Decrement the data content

of register C by 1 (Decrement the counter by

1) C009 : UP INX H ;Increment the memory

location of HL register pair by 1

C00A CMP M ;Compare the data content of register pair HL with data

content of accumulator C00B JNC DOWN : If Carry flag ≠ 1then jump to

memory location C015 C00C 15

C00D C0

C00E MOV D , M ;Copy the data contents of register pair HL to register D

. C00F MOV M , A ;Copy the data contents of

register pair HL to accumulator .

C010 DCX H ;Decrement the memory

location of HL register pair by 1

C011 MOV M , D ;Copy the data contents of register D to register pair HL

C012 INX H ;Increment the memory location of HL register pair

by 1 C013 MVI B, 01 H

C014 01

C015 : DOWN

DCR C ;Decrement the data content of register C by 1

(Decrement the counter by 1)

C016 JNZ UP : ;If counter 0(reg C 0 ) then jump to memory

location C009 C017 09

C018 C0

C019 DCR B ;Decrement the data content of register B by 1

C01A JZ START : If Zero flag = 1 then jump to memory location C000 C01B 00

C01C C0

C01D RST 1 ;Stop the execution

Output :

Before Execution :

C040 = 05 H C041 = 04 H C042 = 03 H C043 = 02 H C044 = 05 H C045 = 01 H

After Execution :

A =

B =

F =

C041 = C042 = C043 = C044 = C045 =

F=

S Z X AC X P X CY