Question

I have to sort an array given by ARY1, Sort it down in the SORT function, then store the sorted array into ARY1S. I chose not to include ARY2, but it would work identical. The SORT should work for both ARY1 AND ARY2. I took the bubblesort algorithm(C++) and tried my best to convert it into assembly, but I have run into errors.

My D0 is length of array

My D1 would be i

My D2 would be j

and D3 is temp

Here is my attempt(this does not work) not only because of syntax issues:

ARY1        DC.B 7       //array size    
            DC.B 56,-5,8,23,-9,18,4 //my array
ARY1S       DS.B 7      //storage size

SORT1       MOVEA.L #ARY1, A0  //moving values into A0               
            MOVEA.L #ARY1S, A1
            MOVE.B (A0)+, D0   //Storing size (7) into D0
            BSR SORT

SORT        CMP.B D0,D1
            BGE DONE

LOOP        CMP.B D0,D2
            BGE INC
            CMP (A1,D2),(A1,D1) //this is not compiling/wrong syntax
            BLE NOTLESS
            MOVE.B (A1,D2),D3
            MOVE.B (A1,D1),(A1,D2)
            MOVE.B D3,(A1,D1)

NOTLESS     ADDQ #1, D2
            BRA LOOP

INC         ADDQ #1, D1
            MOVE.B D1,D2
            BRA SORT

DONE        RTS

Also, if someone can help with the line of code that I commented is not working. Prompting syntax error.

Était-ce utile?

La solution

CMP (A1,D2),(A1,D1) //this is not compiling/wrong syntax

I suggest that you download and use the M68000 Programmer's Reference Manual.
In it, you'll find that the only valid form of CMP is CMP <ea>,Dn. In other words, you'll have to first move the value at (A1, D1) into a D-register, and then compare it against (A1, D2).

Autres conseils

Try this instead:

  CMP.B A1,D2

  CMP.B A1,D1
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top