AnaF
AnaF

Reputation: 63

Reverse an array in assembly language (68HC12)

I need the array to be copied and reversed. The only thing I can do is copy, but I dont understand how to reverse it. Help me please.

That is what I have for now

STACK                   equ     $2000

                        org     $1000
Source_Array            db      $01, $FF, $13, $22, $12, $25, $12, $FE
End_Source

Destination_Array       ds      Destination_Array-Source_Array 
End_Destination
                        org     $2000
Start                   lds     #STACK
                        ldx     #Source_Array
                        ldy     #Destination_Array
Loop                    ldaa    1,x+
                        staa    1,y+

                        cpx     #End_Source
                        bne     Loop
                        swi
                        end

Upvotes: 0

Views: 393

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180947

Copying the array reversed should be as simple as setting y up to the end of the second array and using pre-decrement instead of post-increment for storage; (hoping I'm getting the pre-decrement correct from memory)

STACK                   equ     $2000

                        org     $1000
Source_Array            db      $01, $FF, $13, $22, $12, $25, $12, $FE
End_Source

Destination_Array       ds      Destination_Array-Source_Array 
End_Destination
                        org     $2000
Start                   lds     #STACK
                        ldx     #Source_Array
                        ldy     #End_Destination
Loop                    ldaa    1,x+
                        staa    1,-y

                        cpx     #End_Source
                        bne     Loop
                        swi
                        end

Upvotes: 2

Related Questions