EASy68K  
It is currently Thu Jul 02, 2020 3:20 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Array Sorting Question
PostPosted: Fri Mar 22, 2013 4:56 am 
Offline

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
   ADDA.L   #1,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

{code tags added by admin}


Top
 Profile  
 
PostPosted: Fri Mar 22, 2013 5:35 pm 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group