Table of Contents
ToggleProblem
Write an assembly language program for microcontroller 8051 to find largest number from an array of 10 numbers.
Assume array of the ten bytes is stored in internal memory of 8051 microcontroller from memory location 50H and Store largest number in memory location 60H.
Algorithm
Step 1: Initialize byte counter and memory pointer to read numbers from array.
Step2: Read number from the array.
Step3: Increment memory pointer to read next number.
Step 4: Decrement byte counter.
Step 5: Compare two numbers.
Step 6: If number > next number, then go to step 8.
Step 7: Replace number with next number which is largest.
Step 8: Increment memory pointer to read next number in the array.
Step 9: Decrement byte counter by 1.
Step 10: If byte counter is not equal to zero then go to step 5.
Step 11: Store result.
Step 12: Stop.
Flowchart
Program
CLR PSW.3 ; Clear 3rd bit of PSW.
CLR PSW.4 ; Clear 4th bit of PSW .
; Above steps are used to select register bank 0.
MOV R1, 0AH ; Initialize byte counter.
MOV R0, #50H ; Load 5oh into register R0 to use it as memory pointer.
DEC R1 ; Decrement byte counter by 1
MOV 60H, @R0 ; Store the number in memory location 60h.
REPEAT: INC R0 ; Increment memory pointer by 1.
MOV A, @R0 ; Get the second/next number in accumulator
CJNE A, 60H, SKIP ; If number ≠ next number then go to SKIP.
AJMP NEXT ; else go to NEXT.
SKIP: JC NEXT ; If next number > the previous number then go to NEXT.
MOV 60H, A ; Or replace the next number with previous one.
NEXT: DJNZ R1, REPEAT ; Decrement byte counter by 1, if byte counter≠ 0 then go to REPEAT.
STOP: AJMP STOP ; 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
- 8051 Program for Subtraction of Two 8-Bit Numbers
- 8051 Program for Subtraction of Two 16 bit Numbers
- 8051 Program to Multiply two 8 Bit numbers