Старая процедурка MOVE


Это название выросло из команды TurboBasic XL - копирование памяти. В прошлом мы и решили повторить код. За 30 лет уже много забыто и утеряно, я обратился к приятелю, тот раскопал исходник:

pla
pla
sta 204
pla
sta 203
pla
sta 206
pla
sta 205
pla
pla
tay
begin lda 203,y
sta 205,y
dey
bcs begin (или bcc или beq или bne)
rts

Код адаптирован под Basic и есть один недостаток: копируется не более 255 байт. Более правильный код найден в интернетах:

I know this thread is old, but since I just wasted several hours on this, I figured I'd give back to the group. This is a known working block memory copy (compiles with MADS). I don't know how optimized it is. It's based on an example I found from D.W. Howerton.

 

opt h-
org $600

source = $cb; (cb - cc)
dest = $cd; (cd - ce)
length = $d0; (d0)

 jmp memcpy ; jump entry in case we change something

.proc memcpy ; x=usr($600, source, dest, length)
cld ; make sure were not in BCD mode
pla ; pop number of arguments from USR() into accumulator
cmp #3 ; compare accumulator to 3
stop bne stop ; lock up if we dont have 3 parms (safety mechanism... warm boot tolerant)
pla ; pop hi byte of source into A
sta source+1 ; store hi byte of source into ($cc)
pla ; pop lo byte of source into A
sta source ; store hi byte of source into ($cb)
pla ; pop hi byte of destination into A
sta dest+1 ; store hi byte of destination into ($ce)
pla ; pop lo byte of destination into A
sta dest ; store lo byte of desination into ($cd)
pla ; pop hi byte of length into A
sta length ; store hi byte of length in ($d0)
pla ; pop low byte of length into A
tax ; move A (low byte of length) into X
bne start ; jump to start if X > 0
dec length ; subtract 1 from length
start ldy #0 ; set Y to 0
move lda (source),y ; set A to whatever (source) points to offset by Y
sta (dest),y ; move A to location pointed to by (dest) offset by Y
iny ; increment Y
bne next ; if Y<>0 then (rolled over) then still moving bytes
inc source+1 ; increment hi byte of source
inc dest+1 ; increment hi byte of dest
next dex ; decrement X (lo byte counter)
bne move ; if X<>0 then move another byte
dec length ; weve moved 255 bytes, dec length
bpl move ; if length is still positive go back and move more
rts ; done
.endp

Другой вариант(были команды MOVE и -MOVE).

А ведь столько времени было проведено для создания программы, столько сменено кода. Сейчас решить задачу легко с помощью кросс-средств.

Комментарии