Looks to me like every thing except the inner loop
routine will work (but I don't guarantee anything,
I may have missed something, I often do
except..
Looking at the inner loop, I'm wondering
if you're confused about how an assembler works.
; exchange sort loop
; smallest number in lowest memory location
INNER LDA #$00 ; Start of source of numbers to sort.
label INNER the name of the location of this
LDA instruction and this instruction loads the
accumulator immediate with 0
ie takes the value of the byte (which in this case
will be zero) following the LDA instruction in
the object code (that the assembler puts out) and
puts it in the accumulator
LDX #1 ; Initiate pointers
load the X register immediate with 1
LDX #2 ; Initiate pointers
load the X register immediate with 2, but you didn't
do anything with the 1 and now it's gone, what was
it for?
LDA LPCTR+1 ; Count elements
now this is what makes me think you may be confused
about how an assembler works.
When you told the assembler:
LPCTR = $411
you were naming a constant for you and/or the
assembler to use, not creating a program variable.
sort of like immediate mode in basic.
(I should say here, I don't know what assembler
you're using and not all assemblers are the same
so I can't really be sure, but I think this is the
way it usually works)
so now the assembler looks at this instruction and
probably assumes LPCTR+1 is meant as an address so it
sees that as a load accumulator from address LPCTR+1,
$411+1 in other words this instruction comes out the same
as LDA $412 and loads the accumulator from the location
in memory that's right after the the LPCTR location,
which is the location in memory corresponding to NNUMS
in other words this instrustion is also the same as
LDA NNUMS, and every time you do that instruction in
your loop it's going to load the accumulator from
location $412
ie it doesn't change LPCTR, memory location $411
CMP DATA ; Compare 2 data types
DATA is $400 so you're comparing the the first element
of your list, the contents of memory location $400
(which you intialised to $10) to the value you just
loaded into the accumulator, the value from
location NNUMS (which you initialised to $10)
STA #1 ; Set new smallest pointer
unless your assembler is rather odd, this is a
'store accumulator immediate' instruction
(or something) and there is no such instruction
L2 JSR INNER ; Increment INNER loop counter
label L2 the name of the location of this JSR
now we jump subroutine back to location INNER
you push the current value of the program
counter on to the stack and jump to INNER
so you never get past this point and every
time you get here you increase the number of
bytes on the stack by two
(pretty soon you're going to run out of stack)
BCS L2 ; Loop back to INNER counter
you won't get here, but if by some dark miracle
you should get past the previous instruction
,
you'll branch right back to it 'cause you
just compared $10 to $10 and that should set the
carry and BCS L2 looks at the carry and branches
to L2 if the carry is set
JSR SWAP ; Swap locations
RTS ; End
Maybe I'm misinterpreting your intent in this code
but it looks like you're making mistakes in the
inner loop that you didn't make elsewhere.
And I'm still wondering what an assembler could
make of STA #1
I'm guessing you haven't tryed to assemble it,
but maybe your assembler uses a syntax I'm not
familiar with, and if that's so, a lot of what
I just said about what your code does maybe
rubbish
Did you write the rest of it?
Or is this, like, homework?
"your assignment: right an inner loop for this
sort routine"