1. Write a program to find the factorial of a given number using CALL instruction.
ANS→
MOV R1,#04H
MOV R2,#01H
LCALL FACT
MOV R3,A
FACT:
MOV A,R2
CJNE R1,#00H,UP
SJMP UP1
UP:
MOV B,R1
MUL AB
DJNZ R1,UP
UP1:
RET
END
2. Write a program to shift a 24 bit number stored at 57H-55H to the left logically four places.
Assume that the least significant byte of data is stored in lower address.
ANS→
MOV 57H,#08H
MOV 56H,#07H
MOV 55H,#06H
MOV A,57H
RL A
RL A
RL A
RL A
MOV 57H,A
MOV A,56H
RL A
RL A
RL A
RL A
MOV 56H,A
MOV A,55H
RL A
RL A
RL A
RL A
MOV 55H,A
END
3. Write a program to find the cube of an 8 bit number program.
mov a,#07h
mov b,#07h
mov r0,#07h
mul ab;
mov 40h,a
mov 41h,b
mov r1,a
mov a,b;
mov b,r0;
mul ab;
mov b,a;
mov r2,b;
mov a,r1;
mov b,r0;
mul ab;
mov 50h,a
mov r3,b
mov a,r2
add a,r3
mov b,a
mov 51h,b
end
Implement the above programs in Keil Embedded C also.
1:
ans→
#include<reg51.h>
Int main()
{
Int a,b,ans=0x01,i;
a=P1;
for( i=0x02;i<=a;++i)
{
ans=ans*i;
}
P1=ans;
}
2:-->
#include<reg51.h>
Int main()
{
Int a,b,c;
a=P0,b=P1,c=P2;
P0=a<<4;
P1=b<<4;
P2=c<<4;
}
3:-->
#include<reg51.h>
Int main()
{
Int a,ans=0x01;
a=P0;
ans=a;
for(i=0x00;i<0x02;++i)
ans*=a;
P1=ans;
}