What if you CALL using PC as SRI and another register as SND ?
SND gets PC+1 but PC will get PC, which ... yeah it wil get stuck. So we can detect this special case.
The result is that the next instruction's address will go into any other register, which is useful when starting a loop for example. So the corresponding opcode would be ENTER or ENTRY, useful when you don't want to compute addresses and your loop body has more than 8 instructions.
set R1 42 ; some loop counter entry R2 ; sets R2 to PC+1 ; do something long and useful here add -1 R1 set R2 PC NZ ; end of loop
This looks nicer than
set $+1 R2
Now this increases the pressure on the registers. You could put the address on the stack top for example, but the loop counter would be better suited for this location, as it can be implicitly saved when a call occurs.
The address can be retrieved at the last moment:
set R1 42 ; some loop counter loopentry: ; do something long and stupid here set loopentry R2 add -1 R1 set R2 PC NZ ; end of loop
The total code length is the same but the loop is slower by one instruction. It's not the highest code density ever, but it works.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.