It is currently Thu Apr 02, 2020 1:03 pm

 All times are UTC

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Why does my (a0)+ skip a number?Posted: Thu Mar 07, 2013 5:17 am

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

loop2   cmp.w   d3,d5
beq     loop2Done

move.w  (a0)+,d7
cmp.w   d6,d7
blt     ifState

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

 Post subject: Re: Why does my (a0)+ skip a number?Posted: Thu Mar 07, 2013 5:00 pm

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

 Post subject: Re: Why does my (a0)+ skip a number?Posted: Thu Mar 07, 2013 7:40 pm

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 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