Jump to content

Repeat: Difference between revisions

m
m (→‎Indirect Jump: formatting and clarification of syntax)
Line 27:
 
=={{header|6502 Assembly}}==
===Using a trampoline===
 
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.
 
Line 60:
Once the macro and the underlying subroutine are created, this is very simple to use:
<lang 6502asm>RepeatProc foo,#20 ;perform the subroutine "foo" twenty times.</lang>
===Using self-modifying code===
This version requires that your "wrapper" executes in RAM, so that it can be modified. For this to work, it is assumed that the routine you're using doesn't clobber Y, or require that its parameters are passed in by A or X (so admittedly this method is a bit limited, but if you use the zero page to hold the parameters you can set them up prior to calling the wrapper itself.
<lang 6502asm>RepeatProc:
;input: low byte of desired function address in A
; high byte of desired function address in X
; repeat count in Y
 
STA smc_repeatproc+1
STX smc_repeatproc+2
smc_repeatproc:
jsr $0000 ;this is modified by the STA and STX above.
dey
bne smc_repeatproc
rts</lang>
 
=={{header|68000 Assembly}}==
1,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.