Loops/For with a specified step: Difference between revisions

no edit summary
m (added highlighting and whitespace.)
No edit summary
Line 99:
ENDDO , next i
XPRNT BUF,80 print buffer</lang>
=={{header|6502 Assembly}}==
This loop loads from an array and writes each element to memory addresses $D000, $D002, $D004, $D006, $D008, $D00A, $D00C, $D00E, in ascending order.
 
<lang 6502asm>define ArrayPointerLo $00 ;define some helpful labels.
define ArrayPointerHi $01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
setArray: ;Easy6502 doesn't let us define arbitrary bytes so the best option is to fill the range at runtime.
lda #$10
ldx #0
loop_setArray:
sta $1200,x
clc
adc #$10
inx
cpx #$08
bcc loop_setArray
 
ClearMem: ;clear $D000-$D0FF
lda #0
ldx #0
loop_clearMem:
sta $D000,x
inx
bne loop_clearMem
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; end of prep work, the real code begins here.
 
lda #$12 ;high byte of array address
sta ArrayPointerHi
lda #$00 ;low byte of array address
sta ArrayPointerLo ;these are used to look up the array rather than hard-code it in.
 
 
 
ldx #$0E ;the loop counter, gets decremented twice per iteration to skip the odd addresses.
ldy #7 ;the index into the source array.
 
;on the 6502 looping backwards is almost always faster.
 
loop_fill:
lda (ArrayPointerLo),y ;loads from the array's base address, plus Y
sta $D000,x ;store at $D000+X
dey ;decrement array index
dex
dex ;decrement destination index twice
bpl loop_fill ;if destination index equals #$FF, we are done.
 
brk ;end of program</lang>
 
{{out}}
<pre>
d000: 10 00 20 00 30 00 40 00 50 00 60 00 70 00 80 00
</pre>
 
=={{header|AArch64 Assembly}}==
1,489

edits