Write a program in 68hc11 to sort the array in ascending ord

Write a program in 68hc11 to sort the array in ascending order bubble sort.

Solution

ASM code:

arr EQU 13 ; offset of array base from the top of the stack

arcnt EQU 12 ; offset of array count from the top of the stack

buf EQU 3 ; offset of buf from the top of the stack

in_order EQU 2

inner EQU 1

iteration EQU 0

true EQU 1

false EQU 0

bubble PSHB

PSHA

PSHY

PSHX

DES ; allocate space for local variables

DES ; “

DES ; “

DES ; “

TSY ; set Y to point to the top byte of the stack

LDAA arcnt,Y

DECA ; compute the number of iterations that need to be performed

STAA iteration,Y ; “

ploop LDAA #true ; set in-order flag to true

STAA in_order,Y ; “

LDX arr,Y ; place the array base address in X

LDAA iteration,Y

STAA inner,Y ; initialize inner loop count

cloop LDAA 0,X ; get one element

CMPA 1,X ; compare it with the next element

BLE looptest

* the following 5 instructions swap the two adjacent elements

STAA buf,Y

LDAA 1,X

STAA 0,X

LDAA buf,Y

STAA 1,X

LDAA #false ; reset the in_order flag

STAA in_order,Y ; “

looptest INX ; move the array pointer

DEC inner,Y

BNE cloop

TST in_order,Y

BNE done

DEC iteration,Y

BNE ploop

* the following four instructions deallocate space allocated to local variables

done INS

INS

INS

INS

PULX

PULY

PULA

PULB

RTS

Write a program in 68hc11 to sort the array in ascending order bubble sort.SolutionASM code: arr EQU 13 ; offset of array base from the top of the stack arcnt E
Write a program in 68hc11 to sort the array in ascending order bubble sort.SolutionASM code: arr EQU 13 ; offset of array base from the top of the stack arcnt E

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site