So, long story short i am returning to 68k assembly after a long hiatus. Basically i have been contracted to do some demos on the subject for a local college. So since i worked a lot with it back in the 90s, i figured, should be a small gig to put together a few demos right? And well, it is, as i remember most of the stuff, but now i was writing a small sorter routine which is basically a right pivot quicksort, that i wanted to use as a demo comparison between C and asm code. Seeing as i packed away my manuals many years ago, i tried going from memory, which with age is going a bit fuzzy, but i made it up until this task fine.
What i am now seeing is that i have an array set in memory, that i wish to iterate and sort in-place, thus i want to establish two pointers in a-regs, one to the pivot value, and one to the new pivot position to swap into after partitioning (as per standard quicksorting). The array is defined like this:
arr DC.W 12,16,1,5,14,3,9,2,4,6
As we can see a random selection of word-sized ints
So then i load up the labeled addr in a-reg:
Then i push offsets for begin and end indexes on the stack and call the sort.
There i will pop off the stack, the offsets, and going from memory, doing what i think is the way to index offset by having a 0 displacement:
So now a-reg A2 should hold pointer to the end element, then i do the same, using A3 for begin:
In initial run d1 contains #0
Now, this is ok, for all but one thing... Populating d1,d2 from the stack with the offsets (in this case index*2 for word) gives correct pointer.
But... and here it is strange... When i fetch from the start element pointer, i actually do not get the num 12 as i expected, i get 000C, i.e. 16 decimal. Meaning i get the element at 0+2 bytes from arr label.
move.w (a3),d4 ;test <- WHY is this 16?
d4 has value 000C, second element, but i expected the 12 to go there, as d1 = 0, and displacement is 0.
Looking in the debugger shows that A3 indeed has the first addr of the "arr" label, but still reads as 000C.
Probably i am forgetting something on either declaring a sequence or indexing it... Please give me some hints, before i have to dig out my manuals (which i should do one of these days anyway). Also: Major thanks for the EASy68k program, and for supplying it to the community. Feels like i am a young, fresh engineer again, getting back into it, thanks to this new commision job, and the program makes it that much easier.