Hi. I'm writing a bubble sort in assembly. I have adjacent bytes containing values and I'm looping through them swapping adjacent values when they're out of sequence. My subfunc to swap adjacent bytes is below, but I can't believe this is the most efficient way of doing it. vara is an intermediary variable and FSR points at the upper byte. Is there a trick I'm missing? I've seen the xor trick that allows swapping defined registers thru W only (no intermediary var required), but I don't see how I can do so with relative addressing.
Mod edit: code tags
Code:
swap
movf INDF,w ; set aside upper byte
movwf vara
decf FSR ; move lower byte into w, then into upper byte
movf INDF,w
incf FSR
movwf INDF
decf FSR ; put vara into lower byte
movf vara,w
movwf INDF
return
Last edited by a moderator:

