File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,9 +103,9 @@ inner_loop:
103103 ldi r23, 1
104104 add r22, r23
105105 ld r24, r22 ; r24 = B
106- ; compare A and B (we'll swap if A > B)
107- cp r24, r21 ; sets carry if r24 < r21 (unsigned)
108- brcs no_swap ; branch if carry set => r24 < r21 => A > B? (keep original order)
106+ ; compare A and B (we'll swap if A < B)
107+ cp r21, r24 ; sets carry if r21 < r24
108+ brcs no_swap
109109 ; swap A and B: store B into A's address, A into B's address
110110 st r20, r24
111111 st r22, r21
Original file line number Diff line number Diff line change @@ -55,9 +55,9 @@ This example demonstrates a simple bubble sort algorithm implemented in assembly
5555 ldi r23, 1
5656 add r22, r23
5757 ld r24, r22 ; r24 = B
58- ; compare A and B (we'll swap if A > B)
59- cp r24, r21 ; sets carry if r24 < r21 (unsigned)
60- brcs no_swap ; branch if carry set => r24 < r21 => A > B? (keep original order)
58+ ; compare A and B (we'll swap if A < B)
59+ cp r21, r24 ; sets carry if r21 < r24
60+ brcs no_swap
6161 ; swap A and B: store B into A's address, A into B's address
6262 st r20, r24
6363 st r22, r21
Original file line number Diff line number Diff line change @@ -44,9 +44,9 @@ inner_loop:
4444 ldi r23 , 1
4545 add r22 , r23
4646 ld r24 , r22 ; r24 = B
47- ; compare A and B (we'll swap if A > B)
48- cp r24 , r21 ; sets carry if r24 < r21 (unsigned)
49- brcs no_swap ; branch if carry set => r24 < r21 => A > B? (keep original order)
47+ ; compare A and B (we'll swap if A < B)
48+ cp r21 , r24 ; sets carry if r21 < r24
49+ brcs no_swap
5050 ; swap A and B: store B into A's address, A into B's address
5151 st r20 , r24
5252 st r22 , r21
You can’t perform that action at this time.
0 commit comments