第一個ARM彙編程序——冒泡排序

引用請註明出處:http://blog.csdn.net/int64ago/article/details/7008883

AREA Sort,CODE,READONLY		;declare for code area
	ENTRY					;entry for the whole code
start						;main code flag
	MOV R4,#0				;clear r4
	LDR R6,=src				;r6 point to the begining of numbers
	ADD R6,R6,#len			;r6 point to the end of numbers  
outer					 	;outer loop begining
	LDR R1,=src				;r1 point to the begining of numbers 
inner						;inner loop begining
	LDR R2,[R1]				;get the number in address of r1
	LDR R3,[R1,#4]			;get the number in address next to r1
	CMP R2,R3				;compare two numbers we gotten
	STRGT R3,[R1]			;if the first > the second 
	STRGT R2,[R1,#4]			;exchange the position of two numbers
	ADD R1,R1,#4				;the point of r1 move
	CMP R1,R6				;compare position current  and ending
	BLT inner				;if not meet the ending go on to loop

	ADD R4,R4,#4				;global counter +1
	CMP R4,#len				;compare the current position
	SUBLE R6,R6,#4			;if not meet the ending
	BLE outer				;go on to loop

	AREA Array,DATA,READWRITE ;decare for data area
src	DCD 2,4,10,8,14,1,20	  	;init the original numbers
len	EQU 7*4					;get the length of numbers

	END						;end of whole code

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章