An Example of Programming in Assembly Language for Single-Chip Microcomputers Using Selection Method

Publisher:花海鱼Latest update time:2017-10-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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 

Reference address:An Example of Programming in Assembly Language for Single-Chip Microcomputers Using Selection Method

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

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号