Q1: Program: Write an ALP to move a block of n bytes of data from source (20h) Q5: Write an ALP to add
o add the byte in the RAM at 34h and 35h, store the result in
to destination (40h) using Internal-RAM. the register R5 (LSB) and R6 (MSB), using Indirect Addressing Mode.
ORG 0000H ORG 0000H
MOV R0, #20H MOV R0, #34H
MOV R1, #40H MOV R1, #35H
MOV R3, #05H MOV A, @R0
BACK: ADD A, @R1
MOV A, @R0 MOV R5,A
MOV @R1, A MOV R6, #00H
INC R0 JNC SKIP
INC R1 INC R6
DJNZ R3, BACK SKIP:
HERE: HERE:
SJMP HERE SJMP HERE
END END
Q2: Program: Write an ALP to move a block of n bytes of data from source Q6: Write an ALP to subtract the bytes in Internal RAM 34h & 35h store the result
(2000h) to destination (2050h) using External RAM. in register R5 (LSB) & R6 (MSB).
ORG 0000H ORG 0000H
MOV DPH, #20H MOV R0, #34H
MOV R4, #00H MOV R1, #35H
MOV R5, #50H MOV A, @R0
MOV R6, #05H CLR C
BACK: SUBB A,@R1
MOV DPL, R4 MOV R5, A
MOVX A, @DPTR MOV R6, #00
MOV DPL, R5 JNC SKIP
MOVX @DPTR, A DEC R6
INC R4 SKIP:
INC R5 HERE:
DJNZ R6, BACK SJMP HERE
HERE: END
SJMP HERE Q7: Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and
END store16- bit result in 32h and 33h of Internal RAM.
Q3: Program: Write an ALP To exchange the source block starting with address ORG 0000H
20h, containing N bytes of data with destination block starting with address 40h.
MOV R0, #30H
ORG 0000H MOV R1, #31H
MOV R0, #20H MOV A, @R0
MOV R1, #40H MOV B, @R1
MOV R3, #05H MUL AB
BACK: MOV R0, #32H
MOV A, @R0 MOV R1, #33H
XCH A, @R1 MOV @R0, A
MOV @R0, A MOV @R1, B
INC R0 HERE:
INC R1 SJMP HERE
DJNZ R3, BACK END
HERE: Q8: Write an ALP to perform division operation on 8-bit number by 8-bit number.
SJMP HERE
END ORG 0000H
MOV R0, #30H
Q4:Program: Write an ALP to exchange the source block starting with address
MOV R1, #31H
10h, containing N bytes of data with destination block starting at location 00h.
MOV A, @R0
ORG 0000H MOV B, @R1
MOV R0, #10H DIV AB
MOV R1, #00H MOV 32H, A
MOV R2, #06H MOV 33H, B
MOV DPH, #00H HERE:
BACK: SJMP HERE
MOV DPL, R1 END
MOVX A, @DPTR
XCH A, @R0
MOVX @DPTR, A
INC R0
INC R1
DJNZ R2, BACK
HERE:
SJMP HERE
END
Q9: Write an ALP to separate positive and negative in a given array.
Q11: Write an ALP to arrange the numbers in Ascending & Descending order.
ORG 0000H
MOV R0, #30H ORG 0000H
MOV R3, #05H MOV R0,#30H
MOV R4, #40H MOV R1,#05H
MOV R5, #50H SORT:
LOOP: MOV B,R3
MOV A, @R0 MOV R2,B
JNB ACC.7, POSITIVE PASS:
NEGATIVE: MOV R1,#04H
//MOV R6, A MOV R0,#30H
MOV B, R5 COMPARE:
MOV R1, B MOV A,@R0
MOV @R1, A MOV B,A
INC R5 INC R0
SJMP NEXT MOV A,@R0
POSITIVE: CJNE A,B,CHECK
//MOV R6, A SJMP SKIP
MOV B, R4 CHECK:
MOV R1, B JNC SKIP ;JNC=Ascending AND JC=Descending
MOV @R1, A MOV @R0, B
INC R4 DEC R0
NEXT: MOV @R0, A
INC R0 INC R0
DJNZ R3, LOOP SKIP:
DJNZ R1,COMPARE
HERE: DJNZ R2, PASS
SJMP HERE HERE:
END SJMP HERE
Q10: Write an ALP to separate even or odd elements in a given array.
END
Q12: Write an ALP to find Largest & Smallest number from a given array starting
ORG 0000H
from 20h & store it in Internal Memory location 40h.
MOV R0, #30H
MOV R3, #05H ORG 0000H
MOV R4, #40H MOV R0,#20H
MOV R5, #50H MOV R2,#05H
LOOP: MOV A,@R0
MOV A, @R0 MOV R1,A
JNB ACC.0, EVEN MOV R3,A
ODD: DEC R2
//MOV R6, A LOOP:
MOV B, R5 INC R0
MOV R1, B MOV A,@R0
MOV @R1, A MOV 30H,R1
INC R5
SJMP NEXT CJNE A,30H,COMPARE_MAX
EVEN: SJMP COMPARE_MIN
//MOV R6, A COMPARE_MAX:
MOV B, R4 JC COMPARE_MIN
MOV R1, B MOV R1,A
MOV @R1, A COMPARE_MIN:
INC R4 MOV 35H,R3
NEXT: CJNE A,35H,CHECK_MIN
INC R0 MOV R3,A
DJNZ R3, LOOP SJMP NEXT
HERE: CHECK_MIN:
SJMP HERE JNC NEXT
END MOV R3,A
NEXT:
DJNZ R2,LOOP
MOV 40H,R1
MOV 41H,R3
END
Q13:Write an ALP for Decimal UP-Counter. Q15: Write an ALP for Hexadecimal UP-Counter.
ORG 0000H ORG 0000H
MOV P1,#00H MOV P1,#00H
JMP MAIN JMP MAIN
MAIN: MAIN:
MOV R2,#10 MOV R2,#15
MOV R3,#00H MOV R3,#00H
COUNT_LOOP: COUNT_LOOP:
MOV P1,R3 MOV P1,R3
ACALL DELAY INC R3
INC R3 DJNZ R2,COUNT_LOOP
DJNZ R2,COUNT_LOOP JMP MAIN
JMP MAIN DELAY:
DELAY: MOV R6,#200
MOV R6,#200 DELAY_OUTER:
DELAY_OUTER: MOV R7,#200
MOV R7,#200 DELAY_MIDDLE:
DELAY_MIDDLE: MOV R5,#200
MOV R5,#200 DELAY_INNER:
DELAY_INNER: NOP
NOP NOP
NOP DJNZ R5,DELAY_INNER
DJNZ R5,DELAY_INNER DJNZ R7,DELAY_MIDDLE
DJNZ R7,DELAY_MIDDLE DJNZ R6,DELAY_OUTER
DJNZ R6,DELAY_OUTER RET
RET END
END Q16: Write an ALP for Hexadecimal DOWN-Counter.
Q14:Write an ALP for Decimal DOWN-Counter.
ORG 0000H
ORG 0000H MOV P1,#00H
MOV P1,#00H JMP MAIN
JMP MAIN MAIN:
MAIN: MOV R2,#15
MOV R2,#0FH MOV R3,#0FH
MOV R3,#00H COUNT_LOOP:
COUNT_LOOP: MOV P1,R3
MOV P1,R3 DEC R3
ACALL DELAY DJNZ R2,COUNT_LOOP
INC R3 JMP MAIN
DJNZ R2,COUNT_LOOP DELAY:
JMP MAIN MOV R6,#200
DELAY: DELAY_OUTER:
MOV R6,#200 MOV R7,#200
DELAY_OUTER: DELAY_MIDDLE:
MOV R7,#200 MOV R5,#200
DELAY_MIDDLE: DELAY_INNER:
MOV R5,#200 NOP
DELAY_INNER: NOP
NOP DJNZ R5,DELAY_INNER
NOP DJNZ R7,DELAY_MIDDLE
DJNZ R5,DELAY_INNER DJNZ R6,DELAY_OUTER
DJNZ R7,DELAY_MIDDLE RET
DJNZ R6,DELAY_OUTER END
RET
END
Q17: Write an 8051 C program to find the sum of the first 10 Integer Numbers. Q21: Write an 8051 C Program to rotate the stepper motor in Clock &
Anti-Clockwise direction.
#include<reg51.h>
void main(void) #include <at89c51xd2.h>
{ void delay(void);
unsigned char x; void main(void)
unsigned int sum=0; {
for(x=1;x<=30;x++) while(1)
{ {
sum+=x; P2 = 0x07;
} delay();
P1=sum&0xFF; P2 = 0x08;
P2=(sum>>8)&0xFF; delay();
} P2 = 0x0D;
delay();
Q18: Write an 8051 C program to find the Factorial of a given number.
P2 = 0x0E;
#include<reg51.h> delay();
void main() // To rotate anti-clockwise, reverse
{ the sequence: 0x0E → 0x0D → 0x08 → 0x07
unsigned char num=7; }
unsigned int i; }
unsigned long factorial=1; void delay(void)
for(i=1;i<=num;i++) {
{ int i;
factorial=factorial*i; for(i = 0; i < 30000; i++);
} }
P1=factorial;
Q22: Write an 8051 C program to Generate Sine & Square waveforms using DAC
P2=(factorial&0xFF00)>>8; interface.
}
/*Square Wave*/
Q19: Write an 8051 C program to find the Square of a number (1 to 10) using #include <at89c51xd2.h>
Look-Up Table.
void delay(void);
#include<reg51.h> void main(void)
unsigned char code square_table[11] {
={0,1,4,9,16,25,36,49,64,81,100}; while(1)
void main(void) {
{ P1 = 0x00;
unsigned char num = 6; //Change this value 0-10 delay();
unsigned char result; P1 = 0xFF;
result = square_table[num]; delay();
P1 = result; }
while(1); }
} void delay(void)
Q20: Write an 8051 C program to count the number of Ones and Zeros in two {
consecutive memory locations. int i;
#include <reg51.h> for(i = 0; i < 300000; i++);
void main(void) }
{ /*Sine Wave*/
unsigned char byte1, byte2, i, bitval; #include <reg51.h>
unsigned char ones = 0, zeros = 0; unsigned char code sine_tab[64] = {
byte1 = *(unsigned char *)0x30; 128,140,153,165,177,188,199,209,218,226,234,240,246,
byte2 = *(unsigned char *)0x31; 250,253,255,255,254,252,248,243,237,230,222,213,203,
for(i = 0; i < 8; i++) { 193,182,170,158,146,134,121,109,97,85,73,62,51,41,32
bitval = (byte1 >> i) & 0x01; ,24,16,10,4,0,0,2,5,10,16,24,32,41,51,62,73,85,97,10
if(bitval) ones++; 9,121,134,146,158
else zeros++; };
} void main() {
for(i = 0; i < 8; i++) { while(1) {
bitval = (byte2 >> i) & 0x01; for(unsigned char i = 0; i < 64; i++)
if(bitval) ones++; {
else zeros++; P2 = sine_tab[i];
} for(int j = 0; j < 1000; j++);
P1 = ones; // Number of 1s }
P2 = zeros; // Number of 0s }
while(1); }
}