8051 Programs
8051 Programs
Write and Assembly Language Program (ALP) for the 8051 microcontroller to add two
8-bit numbers, including comments
MOV A, #25H ; Load first 8-bit number (example: 25H) into accumulator A
MOV R0, #34H ; Load second 8-bit number (example: 34H) into register R0
MOV DPTR, #9000H ; Load external memory address 9000H into DPTR
; Exchange R0 and R1
MOV A, R0 ; Move data from R0 to accumulator (A)
XCH A, R1 ; Exchange data between A and R1
MOV R0, A ; Move data from A back to R0
; Exchange R2 and R3
MOV A, R2 ; Move data from R2 to accumulator (A)
XCH A, R3 ; Exchange data between A and R3
MOV R2, A ; Move data from A back to R2
END ; End of the program
4. Write an ALP for a 8051 microcontroller with comments to store 01H, 02H, 03H and
04H in Register R0, R1, R2, R3 respectively.
MOV DPTR, #3000H ; Load the address 3000H into the DPTR register
; Read the contents of the external memory location pointed by DPTR into accumulator (A)
MOVX A, @DPTR ; Move the data from the external memory location (3000H) to A
; Store the contents of A into the internal memory location 22H pointed by R0
MOV R0, #22H ; Load the address 22H into R0
MOV @R0, A ; Move the data from A to the internal memory location pointed by
R0 (22H)
END End of the program
6. Write 8051 instructions with comments to load data 37H and 57 H in ‘A’ and ‘R2’,
respectively and then exchange the contents of register R2 with the contents of A.