EASy68K  
It is currently Thu Apr 02, 2020 12:41 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Mar 07, 2013 5:17 am 
Offline

Joined: Thu Mar 07, 2013 4:57 am
Posts: 2
I want to start off by saying that I really suck at M68K, or programming in that matter.

So.. basically I want to create a bubble sort. I created an array A which contains (5, 1, 2, 3, 4) and put it in a0.
I stopped my program when I realized (a0)+ skips 2 for some reason (this is AFTER swaping 5 and 1)

In other words, if I do move.w (a0)+,d0 three times, d0 will have the value 3 instead of 2 which I want it to have
ALSO after the 5th move.w (a0)+,d0, d0 will have the value 5.

Would like some explanation and thanks

Code:
*-----------------------------------------------------------
* Title      : Me
* Written by : Me
* Date       : Me
* Description: Me
*-----------------------------------------------------------
    ORG    $1000
START:               

    clr.w       d2 ; x counter
    clr.w       d3 ; y counter
   
    move.w      n,d4 ; n numbers
    move.w      n,d5 ; n-1
    sub.w       #1,d5
   
    movea.l     #A,a0 ; An array (5, 4, 3, 2, 1)
   

   

   
loop1   cmp.w   d2,d4 ; compare d2(x) and d4(n)
        beq     done  ; if d2 == d4, x == n
       
        move.w  (a0)+,d6
        add.w   #1,d2 ; d++ (x++)
       
loop2   cmp.w   d3,d5
        beq     loop2Done
       
       
        move.w  (a0)+,d7
        cmp.w   d6,d7
        blt     ifState
       
ifDone  add.w   #1,d3   
        bra     loop2

   
ifState     move.w  d6,(a0) ; swaps 5 and 1
            move.w  d7,-(a0) ; swaps 5 and 1
           
            move.w  (a0)+,d0 ; starts right here****************************** d0 = 1 which i want it to have
            move.w  (a0)+,d0 ; ****************************** d0 = 5 which i want it to have
            move.w  (a0)+,d0 ; ****************************** d0 = 3 which i DONT want it to have
            move.w  (a0)+,d0 ; ****************************** d0 = 4 which i DONT want it to have
            move.w  (a0)+,d0 ; ****************************** d0 = 5 which i DONT want it to have
            bra     ifDone
   
loop2Done  clr.w    d3
           bra      loop1             
           
done    stop    #$2000
   

* Put variables and constants here
A   dc.w    5, 1, 2, 3, 4
n   dc.w    5

    END    START     




Top
 Profile  
 
PostPosted: Thu Mar 07, 2013 5:00 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
foxtrot123 wrote:
Code:
ifState     move.w  d6,(a0) ; swaps 5 and 1
            move.w  d7,-(a0) ; swaps 5 and 1

This code does not swap 5 and 1. A0 is pointing at 2 when this code runs.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Thu Mar 07, 2013 7:40 pm 
Offline

Joined: Thu Mar 07, 2013 4:57 am
Posts: 2
profkelly wrote:
foxtrot123 wrote:
Code:
ifState     move.w  d6,(a0) ; swaps 5 and 1
            move.w  d7,-(a0) ; swaps 5 and 1

This code does not swap 5 and 1. A0 is pointing at 2 when this code runs.


Alright, thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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 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:  
cron
Powered by phpBB® Forum Software © phpBB Group