Example: Selection sorting (descending)
N EQU 10
FIR EQU 40H
SORT:
MOV A, #N;
DEC A
MOV R7, A; Number of outer loops
MOV A, #FIR
MOV R0, A; Array first address
NEXT0:
PUSH ACC; Save the address of the first byte of this round
MOV A, R7
MOV R6, A; Number of inner loops
MOV A, @R0; Take the first byte
NEXT1:
INC R0
MOV B, @R0
CJNE A, B, L1; Compare the first byte with another byte
SJMP L2
L1: JC L2; Greater than or equal to, do not exchange
XCH A, @R0; Less than, exchange
DJNZ R6, NEXT1; The smaller byte is in A, take the next byte to compare with it.
POP B ; one round of comparison ends
MOV R0, B ; restore the address of the first byte of this round
MOV @R0, A ; store the smallest number of this round in the first byte
INC R0 ; the byte address of the next round
MOV A, R0
DJNZ R7, NEXT0 ; next round
RET
Previous article:MCS-51 MCU instruction table (function, machine code, number of bytes, number of machine cycles)
Next article:Improved bubble sorting microcontroller assembly language programming example
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Creating an embedded project using Rust
- I bought another development board with the highest integration, no doubt about it.
- [Elective course to get a gift] Keysight's new "Test and Measurement" series of courses, reservations open in the hot summer! Master-level lecturers live online~
- AD chip output digital signal problem
- AVR assembler, paid help
- What is a smart WiFi module? What are the types and functions of wireless router gateway control modules?
- Comparison of several MicroPython IDEs
- [RVB2601 Creative Application Development] @fxyc87 RVB2601-Snake Game
- Qinheng USB PD and other fast charging protocol power receiving chip CH224 evaluation - the first data study and unboxing
- Analysis of the working principles of seven triode collector DC circuits 4