Deepcopy: Difference between revisions

1,107 bytes added ,  1 year ago
m
Line 19:
* Suitable links to external documentation for common libraries.
<br><br>
 
=={{header|6502 Assembly}}==
Deep copying is very simple on the 6502 - just load a value from memory and store it somewhere else.
<lang 6502asm>LDA $00 ;read the byte at memory address $00
STA $20 ;store it at memory address $20</lang>
 
Now, anything you do to the byte at <tt>$00</tt> won't affect the byte at <tt>$20</tt>.
<lang 6502asm>LDA $00 ;read the byte at memory address $00
STA $20 ;store it at memory address $20
INC $00 ;add 1 to the original
CMP $00 ;compare the copy to the original (we could have done LDA $20 first but they're the same value so why bother)
BNE notEqual ;this branch will be taken.</lang>
 
There is no built-in <code>memcpy()</code> function but it doesn't take much effort to create one. This version can copy up to 256 bytes of memory:
<lang 6502asm>;input:
;$00,$01 = pointer to source
;$07,$08 = pointer to destination
;X = bytes to copy
;(the memory addresses are arbitrary, but each pair of input addresses MUST be consecutive or this won't work.)
memcpy:
LDY #0
memcpy_again:
lda ($00),y
sta ($07),y
iny
dex
bne memcpy_again
rts</lang>
 
 
=={{header|Aime}}==
1,489

edits