Table of Contents
ToggleProgram 1
Problem
Add the two data bytes 50H and 60H. Then load one of the data byte in Accumulator and then add second byte with accumulator.
Flowchart
Program
MOV A, #50H ; Load 50H into accumulator
ADD A, #60H ; Add 60H into accumulator
LOOP: AJMP LOOP ; Stop
Program 2
Problem
Suppose the two data bytes are 40H and 50H stored in Register R2 and R3 of the Bank 1. Add them and store result in Register R4 of Bank 1.
Algorithm
- Step 1: Select Bank 1.
- Step 2: Load first number from R2 to Accumulator.
- Step 3: Add second number from R3 with
- Step 4: Store result to R4.
- Step 5: Stop.
Flowchart
Program
CLR PSW.4 ; Clear 4th bit of PSW
SETB PSW.3 ; Set 3rd bit of PSW
; above steps are used to select register bank 1
MOV A, R2 ; Copy content of accumulator to accumulator
ADD A, R3 ; Add accumulator and R3, result stored into accumulator
MOV R4, A ; Copy the result from accumulator into r4
LOOP: AJMP LOOP ; Stop
Program 3
Problem
Suppose two data bytes are stored in memory location 3000H and 3001H. Write a program to add these two bytes from external memory locations and store result in memory location 3002H of the external memory.
Algorithm
Step 1: Initialize memory pointer using DPTR register with 3000H.
Step 2: Load first number from the memory location 3000H.
Step 3: Increment memory pointer by 1.
Step 4: Load second number from memory location 3001H.
Step 5: Add both numbers.
Step 6: Store Result in memory location 3002H by incrementing memory pointer.
Step 7: Stop.
Flowchart
Program
MOV DPTR, #3000H ; Load 3000h into DPTR
MOVX A, @DPTR ; Copy the data from 3000h to accumulator ;indirectly
MOV R0, A ; Copy content of accumulator into R0
INC DPTR ; Increment DPTR by 1, now DPTR= 3001h
MOVX A, @DPTR ; Copy data from 3001h into accumulator
ADD A, R0 ; Add content accumulator and R0, result in ;accumulator
INC DPTR ; Increment DPTR by 1, now DPTR= 3002h
MOVX @DPTR, A ; Copy the result in accumulator to address 3002h
LOOP: AJMP LOOP ; Stop
Recent posts
Related posts:
- Assembler Directives in 8051 Microcontroller
- Features of 8051 Microcontroller
- Memory Organization of 8051 Microcontroller
- Addressing Modes in 8051 Microcontroller
- Instruction Set in 8051 Microcontroller
- Architecture of 8051 Microcontroller
- PSW Register in 8051 Microcontroller | Program Status Word
- Pin Configuration of 8051 Microcontroller
- The Stack and Stack Pointer in 8051 Microcontroller
- Stack Pointer Data Pointer and Program Counter in 8051 Microcontroller
- Functions of Timing and Control Unit of 8051
- Functions of Ports in 8051 Microcontroller
- Port Structure of 8051 Microcontroller
- Reset Circuit of 8051 Microcontroller
- Registers in 8051 Microcontroller
- Boolean Processor in 8051 Microcontroller
- Power Saving Mode in 8051 | 8051 Power Down and Idle Mode
- 8051 Microcontroller Family
- Program Development Steps in ALP