Repeat: Difference between revisions

m
Line 2,221:
<lang z80>trampoline:
jp (hl) ;despite the parentheses this does NOT dereference HL, it merely acts as "LD PC,HL".</lang>
 
===Using self-modifying code===
This method assumes the routine doesn't use the B register, or restores it before returning. Also, the actual "wrapper" used to repeat the passed function must be in RAM so that its instructions can be modified at runtime.
 
LD HL,myFunc
LD (repeatproc+1),HL
LD B,5 ;repeat count
CALL repeatProc
 
;somewhere far away from here:
repeatProc:
call &0000 ;gets overwritten with the address of MyFunc
djnz repeatProc
ret</lang>
 
=={{header|zkl}}==
1,489

edits