avr-gcc
00000000 <bubble_sort>:
{
uint8_t i;
// Bereich schrumpft von n auf 2
for (i = n; i >= 2; i--)
0: cpi r24, 0x02
2: brcs .+54 ; 0x3a
4: movw r26, r22
6: add r26, r24
8: adc r27, r1
a: sbiw r26, 0x01
{
char max = CHAR_MIN;
c: ldi r20, 0x80
uint8_t j, j_max;
// im Bereich nach MAX suchen
for (j = 0; j < i; j++)
e: ldi r19, 0x00
10: cp r19, r24
12: brcc .+18 ; 0x26
14: movw r30, r22
{
if (a[j] >= max)
16: ld r18, Z+
18: cp r18, r20
1a: brlt .+4 ; 0x20
{
// MAX und Pos. merken
j_max = j;
1c: mov r21, r19
max = a[j_max];
1e: mov r20, r18
20: subi r19, 0xFF
22: cp r19, r24
24: brcs .-16 ; 0x16
}
}
// MAX ans Ende tauschen
a[j_max] = a[i-1];
26: movw r30, r22
28: add r30, r21
2a: adc r31, r1
2c: ld r18, X
2e: st Z, r18
a[i-1] = max;
30: st X, r20
32: subi r24, 0x01
34: sbiw r26, 0x01
36: cpi r24, 0x02
38: brcc .-46 ; 0xc
3a: ret
}
Und hier das Ganze noch mal als ARM7 Code
*** CODE SEGMENT '?PR?bubble_sort?A?main':
285: void bubble_sort (uint8_t n, char * a)
00 STMDB R13!,{R4-R6}
04 MOV R3,R0 ; n
286: {
290: for (i = n; i >= 2; i--)
08 MOV R0,R3 ; n
0C B L_11 ; Targ=0xD4
10 L_12:
291: {
292: char max = CHAR_MIN;
10 MOV R3,#0x0
14 MOV R6,R3 ; max
296: for (j = 0; j < i; j++)
18 B L_16 ; Targ=0x64
1C L_17:
298: if (a[j] >= max)
1C MOV R4,R3 ; j
20 MOV R5,R4,LSL #24 ; j
24 MOV R5,R5,LSR #24
28 MOV R4,R1 ; a
2C LDRB R4,[R4,+R5]
30 MOV R5,R6 ; max
34 MOV R5,R5,LSL #24 ; max
38 MOV R5,R5,LSR #24
3C CMP R4,R5
40 BCC L_14 ; Targ=0x5C
301: j_max = j;
44 MOV R2,R3 ; j
302: max = a[j_max];
48 MOV R4,R2 ; j_max
4C MOV R5,R4,LSL #24 ; j_max
50 MOV R5,R5,LSR #24
54 MOV R4,R1 ; a
58 LDRB R6,[R4,+R5]
304: }
5C L_14:
5C ADD R3,R3,#0x0001 ; j
60 AND R3,R3,#0x00FF
64 L_16:
64 MOV R4,R0 ; i
68 MOV R5,R4,LSL #24 ; i
6C MOV R5,R5,LSR #24
70 MOVR R4,R3 ; j
74 MOV R4,R4,LSL #24 ; j
78 MOV R4,R4,LSR #24
7C CMP R4,R5
80 BCC L_17 ; Targ=0x1C
307: a[j_max] = a[i-1];
84 MOV R3,R0 ; i
88 MOV R4,R3,LSL #24 ; i
8C MOV R4,R4,LSR #24
90 MOV R3,R1 ; a
94 ADD R3,R3,R4 ; a
98 LDRB R3,[R3,#0xFFFFFFFF]
9C MOV R4,R2 ; j_max
A0 MOV R5,R4,LSL #24 ; j_max
A4 MOV R5,R5,LSR #24
A8 MOV R4,R1 ; a
AC STRB R3,[R4,+R5]
308: a[i-1] = max;
B0 MOV R3,R6 ; max
B4 MOV R4,R0 ; i
B8 MOV R5,R4,LSL #24 ; i
BC MOV R5,R5,LSR #24
C0 MOV R4,R1 ; a
C4 ADD R4,R4,R5 ; a
C8 STRB R3,[R4,#0xFFFFFFFF]
309: }
CC SUB R0,R0,#0x0001 ; i
D0 AND R0,R0,#0x00FF
D4 L_11:
D4 MOV R3,R0 ; i
D8 MOV R3,R3,LSL #24 ; i
DC MOV R3,R3,LSR #24
E0 CMP R3,#0x0002
E4 BGE L_12 ; Targ=0x10
310: }
E8 LDMIA R13!,{R4-R6}
EC BX R14
|