0% found this document useful (0 votes)
3 views

EXPERIMENT NUMBER 13

The document describes an experiment to write a mixed language program in Turbo C to separate even and odd numbers from an array using assembly language features. It outlines the theory behind using assembly within C, the algorithm for the program, and provides the source code. The conclusion states that the program successfully executed and verified the output of separating even and odd numbers.

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

EXPERIMENT NUMBER 13

The document describes an experiment to write a mixed language program in Turbo C to separate even and odd numbers from an array using assembly language features. It outlines the theory behind using assembly within C, the algorithm for the program, and provides the source code. The conclusion states that the program successfully executed and verified the output of separating even and odd numbers.

Uploaded by

waghjayesh07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NUMBER :13

TITLE :
Write mixed language program to separate even and odd numbers from an array .

Software required: TURBO C compiler

Theory:
Assembly Language can be Written in C .

C Supports Assembly as well as Higher Language Features so called “Middle Level Language”.

“asm” Keyword is written to indicate that “next followed instruction is from Assembly
Language”.

Many programmers are more comfortable writing in C, and for good reason: C is a mid-level
language (in comparison to Assembly, which is a low-level language), and spares the
programmers some of the details of the actual implementation.

However, there are some low-level tasks that either can be better implemented in assembly, or
can only be implemented in assembly language. Also, it is frequently useful for the programmer
to look at the assembly output of the C compiler, and hand-edit, or hand optimize the assembly
code in ways that the compiler cannot. Assembly is also useful for time-critical or real-time
processes, because unlike with high-level languages, there is no ambiguity about how the code
will be compiled. The timing can be strictly controlled, which is useful for writing simple device
drivers.

In c , every integer will take 2 bytes therefore for accessing any element using from array
assembly pointer should increment and decrement by 2.

Algorithm :

1. Accept array of elements using scanf functions.


2. For every element, check modulus of 2 After bring element into accumulator register
(DIV instruction can be used).
3. If remainder is zero then it is even otherwise it odd number put into respective array.
4. Display respective even and odd arrays.
Program to separate even and odd numbers from an array :.

#include <conio.h>

#include <stdio.h>

#include <stdlib.h>

Void main( )

int arr[10],evn[10],odd[10];

int no ;

char rem

int i, j=0, k=0, l1, l2 ;

clrscr( )

printf (“/n Enter the Array Elements:’);

for (i=0; i<10; i++)

scanf (“%d”,& arr[i])

asm lea si,arr

asm mov cx,0ah

back : asm mov ax,[si]

asm mov no,ax

asm mov bl,02h

asm div bl

asm mov rem,ah

if (rem=1)

odd{j]=no;

j++ ;
l1=j;

else

evn[k]=no;

K++;

l2=k;

asm add si,2

asm loop back

printf(“\n Even Array) ;

for (i=0; i< l2;i++)

printf (“%d”,evn[i]);

printf (”\n Odd Array:’);

for (i=0; i< l1;i++)

printf (“%d”,odd[i]);

getch( );

CONCLUSION: Program executed to separate even and odd numbers from an array and
output is verified.

You might also like