Monday, 18 July 2016

Write a program in assembly language(8086) to matching two strings of same length stored in memory locations.


DATA SEGMENT
        PASSWORD DB 'FAILSAFE'
        DESTSTR DB 'FEELSAFE'
        MESSAGE DB 'String are equal $'
DATA ENDS
CODE SEGMENT
        ASSUME CS:CODE, DS:DATA, ES:DATA
        MOV AX, DATA
        MOV DS, AX
        MOV ES, AX
        LEA SI, PASSWORD
        LEA DI, DESTSTR
        MOV CX, 08
        CLD

        REPE CMPSB
        JNE NOTEQUAL
        MOV AH, 09
        MOV DX, OFFSET MESSAGE
        INT 21h
NOTEQUAL:
        MOV AX, 4C00h
        INT 21h
CODE ENDS
END


Write a program in assembly language(8086) to convert an ASCII input to equivalent hex digit that it represents.


DATA SEGMENT
        ASCII DB 39h
DATA ENDS
CODE SEGMENT
        ASSUME CS:CODE, DS:DATA
START:
        MOV AX, DATA
        MOV DS, AX
        MOV AL, ASCII

        CMP AL, 30h
        JB ERROR
        CMP AL, 3Ah
        JB NUMBER
        CMP AL, 41h

        JB ERROR
        CMP AL, 46h
        JA ERROR
        SUB AL, 37h
        JMP CONVERTED
NUMBER:
        SUB AL, 30h
        JMP CONVERTED
ERROR:
        MOV AL, 0FFh
CONVERTED:
        MOV AX, 4C00h
        INT 21h
CODE ENDS
END START

Write a program in assembly language(8086) to convert the ASCII code to its BCD equivalent.


CODE SEGMENT
        ASSUME CS:CODE
START:
        MOV BL,'5'
        MOV AL,'9'
        AND BL,0Fh
        AND AL,0Fh
        MOV CL,04h
        ROL BL,CL
        OR AL,BL
CODE ENDS
END START

Write a program in assembly language(8086) to find the average of two values stored in memory locations named FIRST and SECOND.


DATA SEGMENT
        FIRST DB 90h
        SECOND DB 78h
        AVGE DB ?
DATA ENDS
CODE SEGMENT
        ASSUME CS:CODE, DS:DATA
START:
        MOV AX, DATA
        MOV DS, AX
        MOV AL, FIRST
        ADD AL, SECOND
        MOV AH, 00h
        ADC AH, 00h
        MOV BL, 02h
        DIV BL
        MOV AVGE, AL
CODE ENDS
END START

Write a program in assembly language(8086) for interchanging the values of two Memory locations.


DATA SEGMENT
        VALUE1 DB 0Ah
        VALUE2 DB14h
DATA ENDS
CODE SEGMENT
        ASSUME CS:CODE, DS:DATA
        MOV AX, DATA
        MOV DS, AX
        MOV AL, VALUE1
        XCHG VALUE2,AL
        MOV VALUE1,AL
        INT 21h
CODE ENDS
END

Write a program in assembly language(8085) for sorting some consecutive memories.


ORG 0100H
        MVI E, 05H
LOOP: LXI H, 300H
DCR E
MOV C, E
LOOP1: MOV A, M
INX H
CMP M
JC LOOP3
LOOP2: MOV B, M
MOV M, A
DCX H
MOV M, B
        INX H
LOOP3: DCR C
JNZ LOOP1
MOV A, E
CPI 01H
JNZ LOOP
HLT
ORG 0300H
DB 13H, 10H, 60H, 34H, 05H (Here 13H=19, 10H=160, 60H=960, 34H=544 )
END

Write a program in assembly language(8085) wheather a number is even or odd.


.ORG  0100H
MVI  A, 10111110B
RRC
JC L1
MVI B, 00B
JMP L2
L1:MVI B, 01B
L2:HLT

Sunday, 17 July 2016

Write a program in assembly language(8085) to find the largest number among three numbers stored in registers.


ORG 1000H
                MVI A, 00H
                MVI B, 08H
MVI C, 02H
MVI D, 09H

MOV A, B
CMP C
JNC LOOP
MOV A, C
JZ LOOP
LOOP:  CMP D
JC LP1
LP1:    MOV A,D
HLT

Write a program in assembly language(8085) to multiply two 8 bit binary numbers by using ADD instruction.


                ORG 1000H
                MVI A, 00H
                MVI B, 02H
                MVI C, 03H
               MVI D, 00H
LOOP:     ADD B
               DCR C
               JNZ LOOP
               HLT
               END

Write a program in assembly language(8085) to check a number for odd or even parity.


                LXI H, 2000H
MOV A, M
INX H
ORA A
JPE EVEN
MVI M, 00H
HLT
EVEN: MVI M, 0FFH
HLT

Write a program in assembly language(8085) to find out the square root of a number.


                MVI C, 01H
        MVI E, 01H
        MVI A, 09H
LOOP: SUB C
        JZ LOOP1
        INR C
        INR C
        INR E
        JMP LOOP
LOOP1:   MOV A, E
        STA 9000h
        HLT

Write a program in assembly language(8085) to find the sum of first 50 even numbers.


                MVI D, 00H
MVI B, 02H
MVI C, 32H
MVI A, 00H
LOOP:     ADD B
JNC LOOP1
INR D
LOOP1:   INR B
INR B
DCR C
JNZ LOOP
HLT
END

Write a program in assembly language (8085) to convert a Hexadecimal number into its equivalent binary.


ORG 1000H
                MVI A, 09H
MVI B, 08H
LXI H, 0150H
LOOP:    RLC
JC LOOP1
MVI M, 00H
INX H
DCR B
JNZ LOOP
LOOP1: MVI M, 01H
INX H
DCR B
JNZ LOOP
HLT
END

Saturday, 16 July 2016

Write a shell script in Linux/Unix to find the biggest number in an array.


echo "ENTER THE NUMBER OF ELEMENTS-"
read e
i=0
while test $i -le `expr $e - 1`
do
echo "ENTER $i ELEMENT-"
read a[i]
i=`expr $i + 1`
done
#SEARCHING THE BIGGEST
lar=${a[0]}
i=1
while test $i -le `expr $e - 1`
do
if test ${a[i]} -gt $lar
then
lar=${a[i]}
fi
i=`expr $i + 1`
done
echo "THE LARGEST NUMBER IS-" $lar


OUTPUT:

ENTER THE NUMBER OF ELEMENTS-
3
ENTER 0 ELEMENT-
6
ENTER 1 ELEMENT-
8
ENTER 2 ELEMENT-
12
THE LARGEST NUMBER IS-12









Write a shell script in Linux/Unix to find the Reverse of a number and check whether the number is Palindrome or not.


echo "ENTER A NUMBER-"
read n
rev=0
t=$n
while test $n -ne 0
do
r=`expr $n % 10`
rev=`expr $rev \* 10`
rev=`expr $rev + $r`
n=`expr $n / 10`
done
echo "THE REVERSE IS-$rev"
if test $rev -eq $t
then
echo "THE NUMBER IS PALINDROME"
else
echo "THE NUMBER IS NOT PALINDROME"
fi


OUTPUT:

ENTER A NUMBER-
121
THE REVERSE IS-121
THE NUMBER IS PALINDROME







Write a shell script in Linux/Unix to solve the expression--x2+7x+12=0


tput clear
echo THE expression is-X^2+7X+12=0
echo roots are---
a=1
b=7
c=12
p=`expr $b \* $b`
s=`expr $a \* $c`
v=`expr $s \* 4`
k=`expr $p - $v`
m=`echo $k ^ 0.5 |bc`
l=`echo -$b + $m |bc`
l1=`echo -$b - $m |bc`
o=`expr 2 \* $a`
x1=`echo $l / $o |bc`
x2=`echo $l1 / $o |bc`
echo X1= $x1
echo X2= $x2


OUTPUT:

THE expression is-X^2+7X+12=0
roots are---
X1= -3
X2= -4









Write a shell script in Linux/Unix to solve the following---S=1.2+2.3+3.4+4.5+.....


tput clear
echo the sum of the series---1.2+2.3+3.4+4.5......
echo--------------------------------------------------
echo enter the no of element
read n
s=0.1
sum=0
i=0
while test $i -lt $n
do
s=`echo $s + 1.1 |bc` 
i=`expr $i + 1`
sum=`echo $sum + $s |bc`
done 
echo $sum


OUTPUT:

the sum of the series---1.2+2.3+3.4+4.5......
--------------------------------------------------
enter the no of element
5
17.0







Write a shell script in Linux/Unix to find the sum of squares of n natural numbers.


tput clear
echo ENTER THE NUMBER OF ELEMENTS-
read n
i=1
sum=0
while test $i -le $n
do
p=`expr $i \* $i`
sum=`expr $sum + $p`
i=`expr $i + 1`
done
echo $sum


OUTPUT:

ENTER THE NUMBER OF ELEMENTS-
5
55



Write a shell script in Linux/Unix to find sum of Digits of a number.


echo "ENTER A NUMBER-"
read n
sum=0
while test $n -ne 0
do
dig=`expr $n % 10`
sum=`expr $sum + $dig`
n=`expr $n / 10`
done
echo "THE SUM OF DIGITS OF $n IS- $sum" 


OUTPUT:

ENTER A NUMBER- 255
THE SUM OF DIGITS OF 255 IS-12









Write a shell script in Linux/Unix to find out the value of nCr.


clear
echo “ Enter values for n & r”
read n
read r
t=0
i=1
a=1
b=1
c=1
d=0
while [ $i –le $n ]
do
a=`expr $a \* $i`
i=`expr $i + 1`
done
i=1
while [ $i –le $r ]
do
b=`expr $b \* $i`
i=`expr $i + 1`
done
i=1
d=`expr $n - $r`
while [ $i –le $d ]
do
c=`expr $c \* $i`
i=`expr $i + 1`
done
i=`expr $b \* $c`
t=`expr $a / $i`
echo “ The Result Is = $t”

OUTPUT:

Enter values for n & r
4
2
The Result Is = 6



















Write a shell script in Linux/Unix to find Factorial of a given number.


echo "ENTER A NUMBER-"
read n
fct=1
i=1
while test $i -le $n
do
fct=`expr $fct \* $i`
i=`expr $i + 1`
done
echo "THE FACTORIAL OF THE NUMBER IS -" $fct


OUTPUT:

ENTER A NUMBER-
5
THE FACTORIAL OF THE NUMBER IS-120







Write a shell script in Linux/Unix to generate Fibonacci series.


tput clear
echo enter the range of the fibonacci series----
read n
echo -------------------------------------------------
a=0
b=1

i=2
echo $a
echo $b
while test $i -lt $n
do

c=`expr $a + $b`
echo $c
a=$b
b=$c
i=`expr $i + 1`
done


OUTPUT:

enter the range of the fibonacci series----
9
-------------------------------------------------
0
1
1
2
3
5
8
13
21











Thursday, 7 July 2016

Write a program in C language that accepts two matrices as input and prints their products


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,i,j,l,k;
clrscr();
printf("\nEnter order of A matrix: ");
scanf("%d %d",&m,&n);
printf("Enter A matrix \n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter order of B matrix: ");
scanf("%d %d",&n,&l);
printf("Enter B matrix \n");
for(i=0;i<n;i++)
for(j=0;j<l;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<l;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf("\n Resultantant matrix is \n");
for(i=0;i<m;i++)
{
for(j=0;j<l;j++)
printf("%6d",c[i][j]);
printf("\n");
}
getch();
}

OUTPUT:




DOWNLOAD

Write a program in C language to implement Linear search


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[20],n,i,m,f=0;
clrscr();
printf("How many numbers: ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&arr[i]);
}
printf("\nEnter the element you want to search: ");
scanf("%d",&m);
for(i=0;i<n;i++)
{
if(arr[i]==m)
{
printf("\n\tItem found at location %d",i+1);
f=1;
break;
}
}
if(f==0)
printf("\nItem not found!!!");
getch();
}


OUTPUT:







Wednesday, 6 July 2016

Write a shell script in Linux/Unix that accepts a text file as input and prints the number of words in the file which have at least one vowel as output

#!/bin/bash
file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"

OUTPUT:


Print Friendly and PDF

Write a program in C language that will accept a Graph as input and will generate its Minimum Cost Spanning Tree


#include<stdio.h>
#include<conio.h>
int a,b,u,v,n,i,j,ne=1;
int visited[10]={0},min,mincost=0,cost[10][10];
void main()
{
clrscr();
printf("\n Enter the number of nodes:");
scanf("%d",&n);
printf("\n Enter the adjacency matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
visited[1]=1;
printf("\n");
while(ne<n)
{
for(i=1,min=999;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]<min)
if(visited[i]!=0)
{
min=cost[i][j];
a=u=i;
b=v=j;
}
if(visited[u]==0 || visited[v]==0)
{
printf("\n Edge %d:(%d %d) cost:%d",ne++,a,b,min);
mincost+=min;
visited[b]=1;
}
cost[a][b]=cost[b][a]=999;
}
printf("\n Minimun cost=%d",mincost);
getch();
}

OUTPUT:



Monday, 4 July 2016

Write a Java program to create an Applet to generate table of 10

import java.applet.Applet;
import java.awt.*;
public class tableof10 extends Applet {
      int count,i;
 
   public void init(){
      this.count=10;
    }

    public void paint(Graphics g) {
        for(i=1;i<=10;i++)
        {
            g.drawString(i+ "* 10 =" +i*10,150,count);
            count=count+20;
        }
   
    }

}

Applet code:

<html>
     <head>
          <title>table of 10</title>
     </head>
     <body>
          <applet code="tableof10.class" height="500" width="500"></applet>
     </body>
</html>

OUTPUT:

Sunday, 3 July 2016

Write a program using JAVA to create an Applet that takes radius of a circle as input and draws the circle in Blue color

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class NewApplet extends Applet implements ActionListener{

    TextField t1;
    Button b1;
    Label l1;
    int r=0;

    public void init() {
        l1 = new Label("Enter radius of circle:");
        t1 = new TextField(5);
        b1 = new Button("Draw Circle");
        add(l1);
        add(t1);
        add(b1);
    b1.addActionListener(this);
    }

   public void paint(Graphics g)
{
    g.drawOval(50, 50, r*2, r*2);
    g.setColor(Color.blue);
    g.fillOval(50, 50, r*2, r*2);
}

public void actionPerformed(ActionEvent e)
{
r= Integer.parseInt(t1.getText());
repaint();
}
}

Applet code:

<html>
     <head>
          <title>circle in Blue color</title>
     </head>
     <body>
          <applet code="NewApplet.class" width="800" height="800"></applet>
     </body>
</html>

OUTPUT:

Print Friendly and PDF

Write a Java program to create two threads T1 and T2. Thread T1 is having priority six and thread T2 is having default priority assigned to it. Implement threads T1 and T2 in such a way that T1 prints table of 2 and T2 prints table of 5

class T1 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"2"+"="+i*2);
}
}

class T2 extends Thread{

public void run(){
        int i;
        for(i=1;i<=10;i++)
        System.out.println(i+"*"+"5"+"="+i*5);
}
}


public class T3 {
 
    public static void main(String[] args){
 
    T1 t1=new T1();
    T2 t2=new T2();
    t1.setPriority(6);
    t1.start();
    t2.start();
    }
 
}

OUTPUT:

1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16
9*2=18
10*2=20
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50

Saturday, 2 July 2016

Write a Java Program to Print Fibonacci Series upto a given Number

import java.util.*;
public class fibonacci {

    public static void main(String[] args) {
           
        Scanner k=new Scanner(System.in);
        System.out.print("Enter range: ");
        int n=k.nextInt();
        int a=0;
        int b=1;
        System.out.print(a+" ");
        System.out.print(b+" ");
     
        for(int i=3;i<=n;i++)
        {
            int c=a+b;
            System.out.print(c+" ");
            a=b;
            b=c;
                 
        }
    }
 
}

OUTPUT:

Enter range: 10
0 1 1 2 3 5 8 13 21 34



Write a java program to find the factorial of a given number

import java.util.*;
public class factorial {

    public static void main(String[] args) {
     
        Scanner k=new Scanner(System.in);
        System.out.print("Enter a number: ");
        int n=k.nextInt();
        float s=1;
        for(int i=1;i<=n;i++)
            s=s*i;
        System.out.println("The factorial is: "+s);
    }
 
}

OUTPUT:

Enter a number: 5

The factorial is: 120.0

Popular Posts