if(*(a+j)>*(a+j+1)) { temp=*a(a+j); *(a+j)=*(a+j+1); *(a+j+1)=temp; }//fill in p
ID: 3547616 • Letter: I
Question
if(*(a+j)>*(a+j+1)) { temp=*a(a+j); *(a+j)=*(a+j+1); *(a+j+1)=temp; }//fill in pep 8 code below that will implement this swap
br main
n: .equate 14 ;counte limit fo the nested limit
a: .word 5 ;begin array storage
.word 4
.word 6
.word 7
.word 8
.word 2
.word 4
.word 3
i: .block 2 ;counter index variable 'i'
j: .block 2 ;counter index variable 'j'
temp: .block 2 ;tempory storage for swap
;main stats here
;start by outputting original array
main: stro str1,d
ldx 0x0000,i
outlp1: deco a,x
charo " ",i
addx 0x0002,i
cpx n,i
brle outlp1
;bubble sort nested loop
lda 0x0000,i
sta i,d ;initialize 'i'
ag1: lda 0x0000,i
sta j,d ;initialize 'j'
ag2: ldx j,d ;use inner loop to compare a[j] with a[j+1]
lda a,x ;using indexed addressing, a-reg contains a[j]
addx 2,i
cpa a,x ;compares a-reg with a[j+1]
brle noswap ;if a[j]<=a[j+1], noswap
;fill in code to swap a[j] and a[j+1]
;update the loop counter variables
noswap: ldx j,d ;inner loop count check
addx 0x0002,i ;j++
stx j,d
cpx n,i
brlt ag2
ldx i,d ;outer loop count check
addx 0x0000,i ;i++
stx i,d
cpx n,i
brlt ag1
;now output the sorted array
stro str2,d
ldx 0x0000,i
outlp2: deco a,x
charo " ",i
addx 0x0002,i
cpx n,i
brle outlp2
stop
str1: .ascii "original array: "
str2: .ascii "sorted array: "
.end
Explanation / Answer
blah
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.