TABLE before the first
0-element. The length of the table
is LENGTH; if there are no 0-elements it
reports the total number of elements in the table. Except
for the limit on the number of elements, and the
terminology, this is the standard C library
strlen() function.
RAM equ $0000
EEPROM equ $f800
org RAM
loopcnt rmb 1
nzcnt rmb 1
org EEPROM
table fcb $0c, $a3, $00, $f0
tabend
length fcb tabend-table
start clr nzcnt
clrb
ldx #table
ldaa length
staa loopcnt
again tstb
bne last
tst loopcnt
bne notend
incb
bra again
notend tst 0,x
bne notzer
incb
bra again
notzer inc nzcnt
inx
dec loopcnt
bra again
last bra last
end start
RAM equ $0000
EEPROM equ $f800
N equ 10
org RAM
i rmb 1
j rmb 1
tmp rmb 1
awry rmb N
org EEPROM
inarr fcb 9, 12, $ff, 13, 0, -37, %01010101, N, 12, tmp
main
* First, copy input to RAM
ldx #inarr * x = &inarr
ldy #0 * y = &awry
ldaa #N * a = N
* * do {
cloop ldab 0,x * b = *x
stab awry,y * awry[y] = b
inx * x++
iny * y++
deca * a--
bne cloop * while (a != 0)
* Now we start the sorting. This is the part that comes from the
* assignment
clr i * i = 0
oloop ldaa i * while...
cmpa #N * ...(i < N)...
bge odone * ...{
clr j * j = 0
ldx #awry * (x = &awry)
iloop ldaa j * while...
cmpa #N-1 * ...(j < N-1)...
bge idone * ...{
ldaa 0,x * if (awry[j] >...
cmpa 1,x * ...awry[j+1])...
ble noswap * ...{
staa tmp * tmp = awry[j]
ldaa 1,x * awry[j] =...
staa 0,x * ...awry[j+1]
ldaa tmp * awry[j+1] =...
staa 1,x * ...tmp
* * }
noswap inc j * j = j + 1
inx * (ix = ix+1)
bra iloop * }
idone inc i * i = i + 1
bra oloop * }
odone bra odone
end main