Table of Contents
ToggleProgram 1: Numbers stored in Register Bank
Problem 1
Suppose the two data bytes are 66H and 55H stored in Register R2 and R3 of the Bank 1. Write an assembly language program for 8051 to subtract number stored in R3 from R2. 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: Subtract second number in R3 from Accumulator.
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.
CLR PSW.7 ; Clear carry flag.
MOV A, R2 ; Copy content of accumulator to accumulator
SUBB A, R3 ; Subtract content of R3 from accumulator and result is stored into accumulator.
MOV R4, A ; Copy the result from accumulator into R4.
LOOP: AJMP LOOP ; Stop.
Program 2: Numbers stored in external memory
Problem 2
Suppose two data bytes are stored in memory location 3000H and 3001H. Write a program to subtract number at 3001H from 3000H 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: Subtract second number from first number.
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.
SUBB A, R0 ; Subtract second number from first, 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
- Addition of Two 8-Bit Numbers in 8051 Microcontroller
- Addition of Two 8 Bit Numbers with Carry in 8051 Microcontroller
- 8051 Program for Addition of Two 16 Bit Numbers
- 8051 Program to Add an Array of Numbers