EASy68K
http://www.easy68k.com/EASy68Kforum/

NEED HELP Sort array ascending order in M68K assembly
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1138
Page 1 of 1

Author:  eschobel [ Sun Nov 11, 2012 5:57 pm ]
Post subject:  NEED HELP Sort array ascending order in M68K assembly

I have a problem with M68 K sorting an array in ascending order:


Here it part of the problem:
Code:
*-----------------------------------------------------------
* Program Number:
* Written by    :
* Date Created  :
* Description   :
*
*-----------------------------------------------------------
START   ORG   $1000
* My sorting code starts here: 



MOVE.W #4,D1                      *load loop counter for list
LEA   LIST , A0                      *A0 points to beginning of LIST


FOR MOVE.W (A0), +, D0                *A0 points to next item on list
DBRA       D1,FOR                           *GO AROUND LOOP AGAIN
//THAT IS ALL I HAVE, REALLY COULD USE HELP
* My sorting code ends here
*
* Code to output data in the list to the Output Window
* Only modify the first two lines for a different test case
   MOVE.B   COUNT,D2   Change it for another array
   LEA   LIST,A0      Change it for another array
LOOP   MOVE.B   (A0)+,D1   Put value to display into D1
   EXT.W   D1      Sign extend D1 to word
   EXT.L   D1            and then to longword
   MOVE   #3,D0      Task number 3 (display [D1])
   TRAP   #15      Display [D1]
   BSR   NEWLINE      Display "/n"
   SUB   #1,D2
   BNE   LOOP
*
   STOP   #$2700

*----------------------------------------------------
* Subroutine to display Carriage Return and Line Feed
*----------------------------------------------------
NEWLINE   MOVEM.L   D0/A1,-(A7)   Push D0 & A1
   MOVE   #14,D0      Task number 14 (diplay null-ended string)
   LEA   CRLF,A1      Put address of string in A1
   TRAP   #15      Display return, linefeed
   MOVEM.L   (A7)+,D0/A1   Restore D0 & A1
   RTS         Return
*----------------------------------------------------
* Data Section
*----------------------------------------------------
   ORG   $2000
COUNT   DC.B   4
LIST   DC.B   2,1,5,4
COUNT1   DC.B   8
LIST1   DC.B   1,2,5,4,8,5,4,2
Count2   DC.B   9
List2   DC.B    10,9,8,7,6,5,4,3,2
* To be completed by you
COUNT3  DC.B   1      
LIST3   DC.B   1      
COUNT4   DC.B   1      
LIST4   DC.B   1      
*
* Do not change the following
CRLF   DC.B   $D,$A,0      Carriage return & line feed, null
   END   START

Author:  lee [ Wed Dec 12, 2012 3:42 am ]
Post subject:  Re: NEED HELP Sort array ascending order in M68K assembly

That's a start, you at least have the loop thing going on and d0 gets the value of each item on the list in turn.

What you need to do now is turn that into something like this

Lee.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/