It is currently Fri Apr 10, 2020 3:29 am

 All times are UTC

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Array Sorting QuestionPosted: Fri Mar 22, 2013 4:56 am

Joined: Fri Mar 22, 2013 4:45 am
Posts: 1
I have a homework assignment to write a program that sorts 2 arrays and saves the size in D0, A0 holds the address of the first element and A1 holds the address of the sorted array. I have some code written and it runs but I am not sure if it is doing what I want. I would appreciate it if someone could let me know if my array is even being sorted, also is there a trap I can use to display my sorted array to output so I can troubleshoot my code sorting a little faster.

Code:
ORG   \$0900   ;Start program at this address
LAB3   CLR.L   D0   ;Clear D0 register
BRA   SORT1   ;Skip over DC instructions

ARY1   DC.B   7   ;Define number of elements in array1
DC.B   23,-9,18,56,-5,8,4
ARY1S   DS.B   7   ;Reserve location for sorted array1

ARY2   DC.B   12
DC.B   \$CC,\$34,\$F4,\$55,\$E3,\$E3,\$3E,\$17,\$15,\$21,\$D7,\$A4
ARY2S   DS.B   12

SORT1   MOVE.B   ARY1,D0 ;D0 holds number of elements in array
LEA   ARY1,A0
ADDA.L  #1,A0 ;A0 holds pointer to first element in array
JSR   SORT

SORT2   MOVE.B   ARY2,D0
LEA   ARY2,A0
JSR   SORT

SORT   MOVEM.L   D0-D4/A0/A1,-(SP)
SUBQ.B   #1,D0
MOVE.B   D0,D2
SORT10   CLR.L   D1
MOVE.B   D0,D3

SORT20   LEA   (0,A0,D3.L),A1
MOVE.B   (-1,A1),D4
CMP.B   (0,A1),D4
BGE   SORT30
MOVE.B   #\$FF,D1
MOVE.B   (0,A1),(-1,A1)
MOVE.B   D4,(0,A1)

SORT30   SUBQ.B   #1,D3
BNE   SORT20

TST.B   D1
BEQ   DONE
SUBQ.L   #1,D2
BNE   SORT10

DONE   MOVEM.L   (SP)+,D0-D4/A0/A1
RTS
END   \$0900

Top

 Post subject: Re: Array Sorting QuestionPosted: Fri Mar 22, 2013 5:35 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
When posting code use the CODE tags

Yes there are TRAPs to print data, you'll have to enumerate through your arrays.

You need to stop the simulator after you run the second sort so it doesn't plough into the subroutine code.

You can view the memory content directly via the simulator, look at that to see the results.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 6 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects