Нашел один пример и залип на алгоритме
;;; Author: Leon Bottou
;;; Public Domain.
cpu 6800
list on
* = $8000
begin = $40
dest = $42
len = $44
ldx #$4000
stx begin
ldx #$1430
stx len
ldx #$6000
stx dest
jsr copy
wai
code
; copy LEN bytes from BEGIN to DEST
copy ldx begin
sts begin
txs
ldx dest
ldab len+1
ldaa len
addb dest+1
adca dest
stab dest+1
staa dest
.1 cpx dest
beq .2
pula
staa 0,x
inx
bra .1
.2 tsx
lds begin
stx begin
clr len
clr len+1
rts
code
;;; Author: Leon Bottou
;;; Public Domain.
cpu 6800
list on
* = $8000
begin = $40
dest = $42
len = $44
ldx #$4000
stx begin
ldx #$1430
stx len
ldx #$6000
stx dest
jsr copy
wai
code
; copy LEN bytes from BEGIN to DEST
copy ldx begin
sts begin
txs
ldx dest
ldab len+1
ldaa len
addb dest+1
adca dest
stab dest+1
staa dest
.1 cpx dest
beq .2
pula
staa 0,x
inx
bra .1
.2 tsx
lds begin
stx begin
clr len
clr len+1
rts
code
Непонятно зачем манипуляции со стеком
; memcpy --
; Copy a block of memory from one location to another.
; Called as a subroutine, note return to saved PC addr on exit
; Entry parameters
; cnt - Number of bytes to copy
; src - Address of source data block
; dst - Address of target data block
cnt dw $0000 ; sets aside space for memory addr
src dw $0000 ; sets aside space for memory addr
dst dw $0000 ; sets aside space for memory addr
memcpy public
ldab cnt+1 ;Set B = cnt.L
beq check ;If cnt.L=0, goto check
loop ldx src ;Set IX = src
lda ix ;Load A from (src)
inx ;Set src = src+1
stx src
ldx dst ;Set IX = dst
sta ix ;Store A to (dst)
inx ;Set dst = dst+1
stx dst
decb ;Decr B
bne loop ;Repeat the loop
check tst cnt+0 ;If cnt.H=0,
beq done ;Then quit
dec cnt+0 ;Decr cnt.H
; loop back and do 256*(cnt.H+1) more copies (B=0)
bra loop ;Repeat the loop
done rts ;Return
Комментарии
Отправить комментарий