Posts

Showing posts with the label 8051 ALP

Do an ALP programming to arrange numbers in ascending order.

ORG 0000H                                ;storing the program from 0000h location in ROM MOV R4,#05H                           ;load 05h in R5 AGAIN:                                       MOV DPTR,#9000H                 ;load 9000h in DPTR(initializing pointer) MOV R3,#05H                           ;load 05h in R3 BACK: MOVX A,@DPTR                   ;fetching data from XRAM MOV B,A                                  ;copy data of A to B INC DPTR             ...

Do programming for following task. Assume that bit P2.2 is used to control an outdoor light and bit P2.5 a light inside a building. Show how to turn on the outside light and turn off the inside one. Test result in SimHardware

ORG 0000H MOV A,#04H MOV P2,A END

Do an ALP programming to arrange numbers in decending order.

ORG 0000H MOV R4,#05H AGAIN:MOV DPTR,#9000H MOV R3,#05H BACK:    MOVX A,@DPTR MOV B,A INC DPTR MOVX A,@DPTR MOV R1,A CJNE A,B,TARGET TARGET:  JC NOEXCHANGE MOV A,B MOVX @DPTR,A MOV A,R1 DEC DPL MOVX @DPTR,A INC DPTR NOEXCHANGE: DJNZ R3,BACK DJNZ R4,AGAIN END  

Do an ALP programming to find largest number in an array.

ORG 0000H MOV R5,#06H MOV DPTR,#4000H MOVX A,@DPTR MOV B,A BACK:INC DPTR MOVX A,@DPTR CJNE A,B,TARGET                                              ;COMPARE THE VALUE OF ACC AND B TARGET: JC NEXT                                                                 ;IF A IS SMALLER THAN B THEN JUMP MOV B,A                                                                ;IF A IS BIGGER THAN B THEN MOV DATA OF A INTO B NEXT:DJNZ R5,BACK  MOV DPTR,#4062H MOV A,B MOVX @DPTR,A END

Do an ALP programming to find smallest number in the array.

ORG 0000H MOV R5,#06H MOV DPTR,#4000H MOVX A,@DPTR MOV B,A BACK:INC DPTR MOVX A,@DPTR CJNE A,B,TARGET                                ;COMPARE THE VALUE OF A AND B TARGET: JNC NEXT                                                ;IF B IS SMALLER THAN A  THEN JUMP MOV B,A                                                   ;IF B IS BIGGER THAN A THEN MOV DATA OF A INTO B NEXT:DJNZ R5,BACK  MOV DPTR,#4062H MOV A,B MOVX @DPTR,A END 

Do programming for following task. A switch is connected to pin P1.7. Check the status of the switch and make the following decision. (a) If SW = 0, send “0” to P2 (b) If SW = 1, send “1“ to P2 Test result in SimHardware

ORG 0000H MOV 90H,#01H                              ;90H IS THE ADDRESS OF P1 PORT MOV A,P1 RRC A                                               ;WE CAN ALSO USED RLC INSTEAD OF RRC JC GO CLR A MOV P2,A SJMP L1 GO:MOV A,#0FFH MOV P2,A L1: END 

Do programming to see if the RAM location 37H contains an even value. If so, send it to P2. If not, make it even and then send it to P2. Test result in Simulator registers windows.

ORG 0000H MOV A,37H MOV B,#02H DIV AB MOV A,B CJNE A,00H,NEXT SJMP GO NEXT:INC 37H GO: MOV P2,37H END 

Do programming to toggle P1 a total of 200 times. Use RAM location 32H to hold your counter value instead of registers R0 –R7. Test result in SimHardware.

ORG 0000H MOV 32H,#0C8H MOV A,#0FFH AGAIN: MOV P1,A MOV R3,#08H BACK: DJNZ R3,BACK CPL A DJNZ 32H,AGAIN END 

Perform the subtraction of two 16-bit numbers using ALP.

;           F6 96 H  ;       -  C6 79 H  ;      =  30 1D H  ;R1=30H(MSB),    R0=1DH(LSB) ORG 0000H CLR C MOV A,#96H MOV R6,#79H SUBB A,R6 JNC GO CPL A INC A GO:MOV R0,A MOV A,#0F6H MOV R7,#0C6H SUBB A,R7 JNC GO1 CPL A INC A GO1:MOV R1,A END  

Perform the addition of two 16-bit numbers using ALP.

v ;   AF 88 H  ;+  89 7F H  ;= 139 07 H  ;R4=01H(MSB),R1=39H(LSB),R0=07H(LSB) ORG 0000H CLR C MOV A,#88H ADD A,#7FH JNC L1 INC R3 L1:MOV R0,A MOV A,#0AFH ADDC A,#89H JNC L2 INC R4 L2:MOV R1,A END 

Use assembly language program to sort an array of N = 06 h bytes of data in descending order stored from location 9000h.

ORG 0000H MOV R4,#06H AGAIN:MOV DPTR,#9000H MOV R3,#06H BACK:    MOVX A,@DPTR MOV B,A INC DPTR MOVX A,@DPTR MOV R1,A CJNE A,B,TARGET TARGET:  JC NOEXCHANGE MOV A,B MOVX @DPTR,A MOV A,R1 DEC DPL MOVX @DPTR,A INC DPTR NOEXCHANGE: DJNZ R3,BACK DJNZ R4,AGAIN END  

Use assembly language program to sort an array of N = 06 h bytes of data in ascending order stored from location 9000h.

ORG 0000H MOV R4,#06H AGAIN:MOV DPTR,#9000H MOV R3,#06H BACK:    MOVX A,@DPTR MOV B,A INC DPTR MOVX A,@DPTR MOV R1,A CJNE A,B,TARGET TARGET:  JNC NOEXCHANGE MOV A,B MOVX @DPTR,A MOV A,R1 DEC DPL MOVX @DPTR,A INC DPTR NOEXCHANGE: DJNZ R3,BACK DJNZ R4,AGAIN END   

Use assembly language program to find the largest element in a given array of N =_06_ h bytes at location 4000h. Store the largest element at location 4062h

ORG 0000H MOV DPTR,#4000H MOV R3,#05H MOVX A,@DPTR MOV B,A BACK:INC DPTR MOVX A,@DPTR CJNE A,B,TARGET TARGET: JC L1 MOV B,A L1: DJNZ R3,BACK MOV A,B MOV DPTR,#4062H MOVX @DPTR,A END  

Write an assembly language program to exchange N = ___h bytes of data at location A: _____h and at location B: _____h. Let N = 05h A: 30h B: 40h

ORG 0000H MOV R3,#05H MOV R0,#30H MOV R1,#40H BACK:MOV A,@R0 MOV R4,A MOV A,@R1 XCH A,R4 MOV @R1,A MOV A,R4 MOV @R0,A INC R0 INC R1 DJNZ R3,BACK END

Write an assembly language program to transfer N = ___ bytes of data from location A: _______h to location B: _______h. Let N = 05h, A: 30h B: 40h

ORG 0000H MOV R3,#05H MOV R0,#30H MOV R1,#40H BACK:MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R3,BACK END

Write a program to copy a block of 10 bytes of data from 35H to 60H

ORG 0000H MOV R3,#0AH MOV R0,#35H MOV R1,#60H BACK:MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R3,BACK END  

Write a program to clear 16 RAM locations starting at RAM address 60H

ORG 0000H MOV R3,#10H CLR A MOV R0,#60H BACK:MOV @R0,A INC R0 DJNZ R3,BACK END 

Do assembly language program to display 0 to 9 digit on seven segment LED display panel in 8051 MCU IDE

  ORG 0000H TARGET:MOV DPTR,#0100H BACK:CLR A MOVC A,@A+DPTR ACALL LOOP MOV P2,A INC DPTR CJNE A,00H,BACK SJMP TARGET ORG 0100H  DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H  LOOP: MOV R0,#003H  L2:MOV R1,#003H  L1:DJNZ R1,L1  DJNZ R0,L2  RET END

Do an assembly language programming to find whether given eight bit number is odd or even. If odd store 00h in accumulator. If even store FFh in accumulator

ORG 0000H MOV A,#31H MOV B,#02H DIV AB MOV R3,B CJNE R3,#00H,NEXT MOV A,#0FFH SJMP L1 NEXT: MOV A,#00H L1: END

Do an assembly language programming to count number of ones and zeros in a eight bit number.

  ;R5=ONES AND R4=ZEROS,R3=COUNTER ORG 0000H MOV R3,#08H MOV 20H,#0F0H MOV A,20H BACK: RRC A ;WE CAN USE RLC ALSO, BOTH WORK FOR THIS PROGRAM JC L1 INC R4 SJMP L2 L1:  INC R5 L2: DJNZ R3,BACK END