Write an assembly program to arrange the numbers in descending order?

All QuestionsCategory: Embedded SystemWrite an assembly program to arrange the numbers in descending order?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 years ago

Code 01:

AREA DESCEND, CODE
ENTRY
MOV R0, #5
OUT LDR R5,= 0X40000000
ADD R6, R5, #1
MOV R3, #4
IN LDRB R1, [R5] LDRB R2, [R6] CMP R1, R2
BCS LOP
MOV R4, R2
MOV R2, R1
MOV R1, R4
LOP STRB R1, [R5] STRB R2, [R6] ADD R5, R5, #1
ADD R6, R6, #1
SUBS R3, R3, #1
BNE IN
SUBS R0, R0, #1
BNE OUT
STOP B STOP
END

 

Code 02:

 

AREA A0, CODE
ENTRY
MOV R6, #5
MOV R0, #0
MOV R1, #6
MOV R5, #0
LDRR7, = 0X40000000
LDRR8, = 0X40000018
LOOP1 SUB R0, R1, #1
MOV R2, R7
MOV R4, R5
LOOP
LDR R3, [R2,#4]!
CMP R4, R3
MOVCC R4, R3
MOVCC R10, R2
SUBS R0, R0, #1
BNE LOOP
SUBS R6, R6, #1
STR R4, [R8], #4
STR R5, [R10] BNE LOOP1
STOP B STOP
END