Repeat: Difference between revisions

Content added Content deleted
Line 25: Line 25:
Example
Example
</pre>
</pre>

=={{header|6502 Assembly}}==

This routine is a bit messy, and assumes the called routine doesn't clobber the zero-page memory used to maintain it. This can be modified to push/pop those values before/after the routine is executed.

<lang 6502asm>macro RepeatProc,addr,count ;VASM macro syntax
lda #<\addr
sta z_L ;a label for a zero-page memory address
lda #>\addr
sta z_H ;a label for the zero-page memory address immediately after z_L
lda \count
jsr doRepeatProc
endm

doRepeatProc:
sta z_C ;another zero-page memory location
loop_RepeatProc:
jsr Trampoline_RepeatProc
dec z_C
lda z_C
bne loop_RepeatProc
rts

Trampoline_RepeatProc:
db $6c,z_L,$00
;when executed, becomes an indirect JMP to the address stored at z_L and z_H. Some assemblers will let you type
;JMP (z_L) and it will automatically replace it with the above during the assembly process.
;This causes an indirect JMP to the routine. Its RTS will return execution to just after the "JSR Trampoline_RepeatProc"
;and flow into the loop overhead.</lang>



=={{header|Ada}}==
=={{header|Ada}}==