Skip to content

Commit c4a5bc5

Browse files
authored
Merge pull request #4 from sql-hkr/fix/#3
Fix #3
2 parents 7aceece + a1f52bc commit c4a5bc5

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

‎docs/examples/bubblesort.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

‎examples/bubblesort.asm‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)