Working on...

your queries, use contact form

21 Oct 2020

C-language program (CLP) to perform basic arithmetic operations like addition, subtraction, multiplication and division

//CLP to perform basic arithmetic operations like addition, subtraction, multiplication and division

 

# include<reg51.h>

void main(void)

{

unsigned char x,y,z, a,b,c, d,e,f, p,q,r; //define variables

 //addition

x=0x12; //first 8-bit number

y=0x34; //second 8-bit number

P0=0x00; //declare port 0 as output port

z=x+y; // perform addition

P0=z; //display result on port 0

 //subtraction

a=0x12; //first 8-bit number

b=0x34; //second 8-bit number

P1=0x00; //declare port 1 as output port

c=b-a; // perform subtraction

P1=c; //display result on port 1

 //multiplication

d=0x12; //first 8-bit number

e=0x34; //second 8-bit number

P2=0x00; //declare port 2 as output port

f=e*d; // perform multiplication

P2=f; //display result on port 2

 //division

p=0x12; //first 8-bit number

q=0x34; //second 8-bit number

P3=0x00; //declare port 3 as output port

r=q/p; // perform division

P3=r; //display result on port 3

 while(1);

}

  

OR simplified one

 

# include<reg51.h>

void main(void)

{

unsigned char x,y,z, a,b,c; //define variables

 x=0x12; //first 8-bit number

y=0x34; //second 8-bit number

P0=0x00; //declare port 0 as output port

P1=0x00; //declare port 1 as output port

P2=0x00; //declare port 2 as output port

P3=0x00; //declare port 3 as output port

z=x+y; // perform addition

P0=z; //display result of addition on port 0

a=y-x//perform subtraction

P1=a// display result of subtraction on port 1

b=x*y// perform multiplication

P2=b//display result of multiplication on port 2

c=y/x//perform division

P3=c // display result of division on port 3

while(1);

}

 

you can find keil simulation of same in following video  

 

 

No comments:

Post a Comment