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

Program 1

Uploaded by

Siva Balan
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)
19 views

Program 1

Uploaded by

Siva Balan
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/ 5

5)BINARY ADDITION AND SUBTRACTION OF 16-BIT NUMBERS

5a) BINARY ADDITION OF 16-BIT NUMBERS WITHOUT CONDITIONAL FLAG:


global start
start:
MOV R0, #6 @R0=6
MOV R1, #7 @R1=7
ADD R2, R2, R1 @R2=R0+R1
.data

BINARY ADDITION OF 16-BIT NUMBERS USING CONDITIONAL FLAG:


. global start
_start:
MOV R0, #6 @Re=6
MOV R1, #7 @R1=7
ADDS R2, R0, R1 @R2=R0+R1
.data

5b) BINARY SUBTRACTION OF 16-BIT NUMBERS USING CONDITIONAL FLAG:


. global start
_start:
MOV R0, #4 @R0=4
MOV R1, #5 @R1=5
SUBS R2, R0, R1 @R2-R1
.data

6a) factorial
#include <stdio.h>
int main ()
{
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf ("%d", &n) ;
if (n < 0)
else {
for (i = 1; i <= n; ++i) {
fact *= i;
printf("Error! Factorial of a negative number doesn't exist.");
}
printf("Factorial of % = %llu", n, fact);
}
}
return 0;

6b) largest elements


#include <stdio.h>
int main ()
{
int n, i,sum, a[101;
printf ("total no of elements:");
scanf ("%d",&n);
for (i=0;i<=n;i++)
{
scanf ("%d", &a[i]);
}
printf("elements in array:");
for (i=0;i<=n;i++)
{
printf ("%d", a[i]);
}
{
for (i=0:i<=n:i++)
sum=sum+a[il;
}
printf("sum is:", sum);
return O;
}

7) carry look-ahead adder


#include‹stdio.h>
int get1(int a)
{
char ch='B';
if (a==1)
ch='A';
do
{
printf("\n\tENTER VALUE OF %c:", ch);
scanf ("%d", &a);
if (a<=0)
printf("\n\t\t!INVALID NUMBER. ENTER VALUE (O< A)!");
}while (a<=0);
return (a);
}
int and(int a, int b)
{
int c;
if (a<b)
с=a;
else
c=b;
return (c);
7b) ripple carry adder
#include <stdio.h>
int (int a, int i)
{
return ((a & (1 << i)) >> i);
}
/*
* Adds bits a and b, taking into account the carry.
*/
int sum (carry_in, a, b)
{
return ((carry_in ^ a) ^ b) ;
}
/*
* Figures out what the carry-over is.
*/
int carry (carry_in, a, b)
{
return (carry_in & a) & b;

8)Floating point addition


#include<stdio.h>
#include<conio.h>

void main( )
{
//floating variables declaration
float num1,num2,sum;
clrscr( );

//asking user to enter first floating number


printf("Enter first number: ");
scanf("%f",&num1); //reading the float number

//asking user to enter second floating number


printf("Enter second number: ");
scanf("%f",&num2); //reading the second float number

//simple addition logic to add two float numbers


sum=num1+num2;

//printing sum of the two float numbers


printf("Sum of two numbers = %f",sum);
getch( );
}
8B)Subtraction
#include<stdio.h>
int main()
{
float a,b,sub;
printf("Enter two numbers: ");
scanf("%f%f",&a,&b);
sub=a-b;
printf("The result is = %f",sub);
return 0;
}

10) Array Multiplier


#include <stdio.h>

int binaryproduct(int, int);

int main()
{

long binary1, binary2, multiply = 0;


int digit, factor = 1;

printf("Enter the first binary number: ");


scanf("%ld", &binary1);
printf("Enter the second binary number: ");
scanf("%ld", &binary2);
while (binary2 != 0)
{
digit = binary2 % 10;
if (digit == 1)
{
binary1 = binary1 * factor;
multiply = binaryproduct(binary1, multiply);
}
else
binary1 = binary1 * factor;
binary2 = binary2 / 10;
factor = 10;
}
printf("Product of two binary numbers: %ld", multiply);
return 0;
}

int binaryproduct(int binary1, int binary2)


{
int i = 0, remainder = 0, sum[20];
int binaryprod = 0;

while (binary1 != 0 || binary2 != 0)


{
sum[i++] =(binary1 % 10 + binary2 % 10 + remainder) % 2;
remainder =(binary1 % 10 + binary2 % 10 + remainder) / 2;
binary1 = binary1 / 10;
binary2 = binary2 / 10;
}
if (remainder != 0)
sum[i++] = remainder;
--i;
while (i >= 0)
binaryprod = binaryprod * 10 + sum[i--];
return binaryprod;
}

You might also like