On the zero 1000 bytes front, my 6502 solution is not significantly different from that presented by Chromatix, (although I tend to use ZP more than the 2-register count there), so I did it in Sweet16 - possibly not in the true spirit of 6502 code, but it is present in Apple II's and I'm using it in my little SBC, so...
Code: Select all
; CC0 license.
.export fill1000
.proc fill1000
jsr strout
.byte "Fill 1000",13,10,0
goSweet16
sub r0 ; Set r0 to zero
set r1,$5000 ; Start address
set r2,1000 ; Bytes to fill
fill: std @r1 ; Store double (2 bytes) from r0 @r1; r1 += 2
dcr r2
dcr r2
bnz fill
exSweet16
rts
.endproc
and a test run by firstly filling RAM with $AA, then checking:
Code: Select all
% 4ff0.5400
4FF0: AA AA AA AA AA AA AA AA | |
4FF8: AA AA AA AA AA AA AA AA | |
5000: AA AA AA AA AA AA AA AA | |
5008: AA AA AA AA AA AA AA AA | |
...
53E0: AA AA AA AA AA AA AA AA | |
53E8: AA AA AA AA AA AA AA AA | |
53F0: AA AA AA AA AA AA AA AA | |
53F8: AA AA AA AA AA AA AA AA | |
5400: AA AA AA AA AA AA AA AA | |
run the code, and check again:
Code: Select all
% r
Fill 1000
% 4ff0.5400
4FF0: AA AA AA AA AA AA AA AA | |
4FF8: AA AA AA AA AA AA AA AA | |
5000: 00 00 00 00 00 00 00 00 | |
5008: 00 00 00 00 00 00 00 00 | |
...
53D8: 00 00 00 00 00 00 00 00 | |
53E0: 00 00 00 00 00 00 00 00 | |
53E8: AA AA AA AA AA AA AA AA | |
53F0: AA AA AA AA AA AA AA AA | |
53F8: AA AA AA AA AA AA AA AA | |
5400: AA AA AA AA AA AA AA AA | |
I've snipped lots of duplicate lines of output. Also note the goSweet16 and exSweet16 are macros that enter sweet16 mode (jsr sweet16) and an assembler directive to assemble sweet16 opcodes, and the reverse.
It's 17 bytes of code including the jsr and rts, obviously much slower than native 6502 though, but if desperate, I could save a byte by changing the std into st to store a single byte, then only one dcr needed. It would be a little slower that way.
Cheers,
-Gordon
-edit to say-
Ps. Just realised I can save that byte anyway, since we'r filing 1000 bytes, half that is 500, so set r2, 500 and remove one of the dcr's.