Question: Write a PIC18 assembly program that uses an array of signed integers of 10 elements and sort them in ascending order. Create a subroutine that

Write a PIC18 assembly program that uses an array of signed integers of 10 elements and sort them in

ascending order. Create a subroutine that receives the address of the array as input and performs the

sorting operation. You could implement the bubble sort algorithm to implement the sorting subroutine.

; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR

INCLUDE "P18F452.inc"

RES_VECT CODE 0x0000 ; processor reset vector

GOTO START ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED

MYVARS UDATA_ACS

Temp RES 1

Temp1 RES 1

flag RES 1

x RES 20

MAIN_PROG CODE ; let linker place main program

START

movlw D'50'

movwf x

clrf x+1

movlw D'20'

movwf x+2

clrf x+3

movlw D'60'

movwf x+4

clrf x+5

movlw D'40'

movwf x+6

clrf x+7

movlw D'30'

movwf x+8

clrf x+9

movlw D'10'

movwf x+D'10'

clrf x+D'11'

movlw D'100'

movwf x+D'12'

clrf x+D'13'

movlw D'90'

movwf x+D'14'

clrf x+D'15'

movlw D'80'

movwf x+D'16'

clrf x+D'17'

movlw D'70'

movwf x+D'18'

clrf x+D'19'

lfsr FSR0, x

loop1 ;sort array

movlw 0x30 ;starts here

movwf FSR0

loop2 ; comparar si es grande

movf FSR0,W

subwf flag,W

btfsc STATUS,Z

return

movf INDF0,W

movwf Temp

incf FSR0,f

movf INDF0,W

subwf Temp,W

btfsc STATUS,Z

goto loop2

btfss STATUS,0

goto loop2

goto loop3

loop3 ; cambiar el valor

movf INDF0,W

movwf Temp1 ;Cambio

movf Temp,W ;cambio

movwf INDF0

decf FSR0,f ;cambio

movf Temp1,W

movwf INDF0

goto loop1

GOTO $ ; loop forever

END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!