EmbeddedSystemProgram Assembly and c program. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Friday 8 May 2020

EmbeddedSystemProgram Assembly and c program.

1.Write an assembly language program for addition, subtraction and
multiplication of two 16 bit numbers.

;ADDITION OF 16BITS

;MOV R1,#0ABH
;MOV R2,#012H
;MOV R3,#026H
;MOV R4,#78H
;MOV A,R1
;ADD A,R3
;MOV R6,A
;MOV A,R2
;ADDC A,R4
;MOV R7,A

;SUBSTRACTION OF 16BITS

;MOV R1,#0ABH
;MOV R2,#012H
;MOV R3,#026H
;MOV R4,#78H
;MOV A,R2
;SUBB A,R4
;MOV R6,A
;MOV A,R1
;ADDC A,R3
;MOV R7,A

##Multipling 16 bit numbers##
ORG 0000H
MOV R0,#0FFH ;MSB1
MOV R1,#0EFH ;MSB2
MOV R2,#0FFH ;LSB1
MOV R3,#9DH  ;LSB2
MOV A,R2
MOV B,R3
MUL AB
MOV R4,A
MOV R5,B
MOV A,R2
MOV B,R1
MUL AB
MOV R6,B
ADDC A,R5
MOV R5,A
MOV A,R1
MOV B,R4
MUL AB
ADDC A,R5
MOV R5,A
MOV A,B
ADDC A,R6
MOV R6,A
MOV A,R1
MOV B,R2
MUL AB
ADDC A,R6
MOV R6,A
MOV A,B
ADDC A,#00H
MOV R7,A

2. Implement an assembly language program to print sum of first “n”
natural numbers.
ORG OOOOh
    LJMP main
    ORG 0x40h
main:
    MOV R0,#0Ah      ;
    MOV B,R0
    INC R0
    MOV A,R0
    MUL AB           
    MOV B,#02h
    DIV AB           
    MOV R4,A

3. Write an assembly language program to check whether the given
number is EVEN or ODD.
  
   ORG 000H
    MOV A,#02DH
    RRC A 
    JC  ODD
    MOV A,#00H 
  SJMP EVEN         
ODD: MOV A,#01H
EVEN:  NOP


4. Write a program in Edsim to find factorial of a number.
ANS-->
MOV R7,A
FACT:
MOV A,R7
CJNE R1,#00,UP
SJMP UP1
UP:
MOV B,R1
MUL AB
DJNZ R1,UP
UP1:
RET

5. Write a program to generate the sum of Fibonacci series for n
terms.
ORG 0000H
LJMP MAIN
ORG 40H
MAIN: MOV R0,#40H
MOV R3,#8H
MOV R1,#00H
MOV @R0,#0H
INC R0
MOV @R0,#01H
MOV R2,#01H
LABEL2: INC R0
MOV A,R1
ADD A,R2
MOV @R0,A
MOV B,R2
MOV R1,B
MOV R2,A
DJNZ R3,LABEL2
END



Write the C Program in Keil Embedded C:

1. Write a C program for the 8051 to:
a. addition of 8-bit two numbers and show the output on port P1.
ans→
#include
int main()
{
unsigned char x,y,z=0;
x=0x44;
y=0x22;
P1=0x00;
z=x+y;
P1=z;
}

b. addition of 16-bit two numbers and show the output on port P1 &P2.
ans→
#include
int main()
{
int a,b,c,d,ans1,ans2;
a=0x02;
b=0x30;
c=0x40;
d=0x12;
P0=P1=P2=0;
ans1=a+b;
if(ans1 > 0xff)
ans2=0x01;
ans2=ans2+c+d;
if(ans2 > 0xff)
P0=0x01;
P1=ans1;
P2=ans2;

c. addition of 8-bit two numbers. Take input from port p1 & P2 and show result on
portP3.
ANS--->
#include
int main()
{
char a,b,ans=0;
a=P1,b=P2;
ans=a+b;
P3=ans;
}

d. addition of 16-bit two numbers. Take input from port P1, P2 & P3, P4 and display
result on port P3 & P4.
ans→
#include
int main()
{
int a,b,c,d,ans1,ans2;
a=P0,b=P1,c=P2,d=P3;
ans1=a+b;
if(ans1 > 0xff)
ans2=0x01;
ans2=ans2+c+d;
if(ans2 > 0xff)
P0=0x01;
P2=ans1;
P3=ans2;

2.Write a program in Keil Embedded C to find factorial of a number. Show
Output on ports.
int main()
{
int a,b=1,c,d,ans1,ans2,i;
a=P0;//p0=N;
for(i=1;i<=a;i++)
 a=a*i;
P1=a;
}

3. Write a program to generate the sum of Fibonacci series for n term,
where input is taken from port.
#include
int main()
{
int a,b,c,d,ans1=1,ans2;
a=P0;// P0=0
b=P1;//P1=1;
c=P2;//P2=N;
P3=0
d=0;
for(i=0;i
{
d=a+b;
a=b;
b=d;
ans1=ans1+b;
P3=b;
P2=ans1;



}