Hi,
I am a first year student & I am very very new to asm. I had 5 questions to submit. I did 4. Which were loops, while ,if else etc. I need to sort 10 intergers in an array. I have been serfing the web all week-end & dicovered there are so many algorithyms for sorting and some have been mofified to add to my confusion. I have to submit my paper tomorrow so I am under pressure. The feedback I am getting is that the Bubble is the shortest to write. The 68000 code does not include the swap function so I am stuck. Any help to start would be greatly appreciated.

elgan

This is my attempt
  ORG $100                            ; starting in this area
MYARRAY DC.B 15,20,90,13,12,77,61,22,33,18
    MOVEA #MYARRAY,A0
    MOVE  #1,D0
    MOVE  #0,D1
LOOP CMP.B  (A0),D0
    BGT    EXIT
    ADD.B  (A0)+D1
    BRA    LOOP
    EXIT
Posted on 2008-01-09 12:47:12 by elgan
Most of us don't appreciate people asking us for help in writing their assignments or homeworks. What you have to do though as far as sorting is concerned, is just to start from the beginning of the array. Then compare the first item with the last, if the second item is smaller than the first, XCHG them with each other. Then have another loop inside the first loop that will navigate in the array but from the next item. This could be confusing while explained but here it the pseudo-code for it:



Var
  TEMP, I, J  : INTEGER;
  ARRAY1      : ARRAY [0..9] OF INTEGER;

  FOR I := LOW(ARRAY1) TO HIGH(ARRAY1) DO
    BEGIN
      FOR J := I + 1 TO 9 DO
        IF (ARRAY1 < ARRAY1) THEN
          BEGIN
            TEMP := ARRAY1;
            ARRAY1 := ARRAY1;
            ARRAY1 := TEMP;
          END;
    END;
Posted on 2008-01-09 13:20:46 by XCHG

Most of us don't appreciate people asking us for help in writing their assignments or homeworks.


IF they show no effort on their behalf. So far, elgan has only asked where to start.
Posted on 2008-01-09 14:31:02 by SpooK


Most of us don't appreciate people asking us for help in writing their assignments or homeworks.


IF they show no effort on their behalf. So far, elgan has only asked where to start.


:oops: Yeah Spook is right :roll:
Posted on 2008-01-09 15:07:50 by XCHG

This is my attempt
  ORG $100                            ; starting in this area
MYARRAY DC.B 15,20,90,13,12,77,61,22,33,18
    MOVEA #MYARRAY,A0
    MOVE  #1,D0
    MOVE  #0,D1
LOOP CMP.B  (A0),D0
    BGT    EXIT
    ADD.B  (A0)+D1
    BRA    LOOP
    EXIT
Posted on 2008-01-11 03:41:46 by elgan
Hmm, looks familiar...
Posted on 2008-01-13 11:41:42 by SpooK
This is my implementation attempt of XCHG's code:
SORT: ; A0 = integer (word) array's base address; D0 = number of elements
  ADD.L   D0, D0
  ADD.L   A0, D0
  BRA     CHECK_END

  LOOP:
    MOVE.W  (A0), D2

    INNER_LOOP:
      MOVE.W  (A1)+, D3
      CMP.W   D2, D3
      BGE     NEXT

      MOVE.W  D2, (#-2,A1)
      EXG     D2, D3

    NEXT:
      CMPA.L  D0, A1
      BNE     INNER_LOOP

    MOVE.W  D2, (A0)+

  CHECK_END:
    LEA     (#2,A0), A1
    CMPA.L  D0, A1
    BLO     LOOP

DONE:
  RTS


Some notes: This is the first 68000 code ever written by me so if it has no bugs it is a miracle. Also note that since I have no 68000 assembler I even don't know if it assembles.

My references was:
http://www.tigernt.com/onlineDoc/68000.pdf
http://en.wikibooks.org/wiki/Programming:68K_assembly
http://www.pwalsh.net/cs/programming_the_68000.htm (Site of SpooK's link)

PS: BTW, writting for 68000 is an enjoyable experience  :shock:

Another link that I found later MOTOROLA M68000 FAMILY Programmer’s Reference Manual (Includes CPU32 Instructions)
Posted on 2008-01-13 14:27:39 by LocoDelAssembly