0% found this document useful (0 votes)
2 views

8051 Programs

The document contains a series of assembly language programs for the 8051 microcontroller, each demonstrating different operations such as adding two 8-bit numbers, loading and incrementing values in external memory, exchanging data between registers, and copying data from external to internal memory. Each program includes comments explaining the purpose of each instruction. The document serves as a practical guide for programming the 8051 microcontroller using assembly language.

Uploaded by

ashkf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

8051 Programs

The document contains a series of assembly language programs for the 8051 microcontroller, each demonstrating different operations such as adding two 8-bit numbers, loading and incrementing values in external memory, exchanging data between registers, and copying data from external to internal memory. Each program includes comments explaining the purpose of each instruction. The document serves as a practical guide for programming the 8051 microcontroller using assembly language.

Uploaded by

ashkf
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

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

ADD A, R0 ; Add contents of A and R0, result stored in A

MOV R1, A ; Store the result in register R1

END ; End of the program

2. Write an ALP for an 8051 microcontroller with comments to load 40 H in external


memory location 9000H and increment the content of the memory location.

MOV DPTR, #9000H ; Load external memory address 9000H into DPTR

MOV A, #40H ; Load 40H into accumulator A

MOVX @DPTR, A ; Store 40H into external memory location 9000H

MOVX A, @DPTR ; Read the content from 9000H into A

INC A ; Increment the content of A

MOVX @DPTR, A ; Store the incremented value back to 9000H

END ; End of the program


3. Write an ALP to store data in R0, R1, R2 and R3 and exchange the data
stored in register R0 with R1 and R2 with R3.
MOV R0, #12H ; Load data 12H into R0
MOV R1, #34H ; Load data 34H into R1
MOV R2, #56H ; Load data 56H into R2
MOV R3, #78H ; Load data 78H into R3

; 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 R0, #01H ; Load 01H into register R0


MOV R1, #02H ; Load 02H into register R1
MOV R2, #03H ; Load 03H into register R2
MOV R3, #04H ; Load 04H into register R3
END ; End of the program
5. Write 8051 instructions with comments to copy the contents of the external data memory
location (3000H) pointed by the DPTR register to the internal data memory location (22H)
pointed by R0.

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.

; Load data into A and R2


MOV A, #37H ; Load 37H into the accumulator (A)
MOV R2, #57H ; Load 57H into register R2
; Exchange the contents of A and R2
XCH A, R2 ; Exchange the contents of A and R2
END

You might also like