Understanding the unfamiliar RST instruction
I realized I did not know anything about the RST instruction. Is it kind of special CALL instruction ? Does it have to be used only when dealing with interrupts ? etc.
Thanks to pulkomandy who had to dig deeply around it while working on its Caprice Reloaded project, he was able to give me precise details about it. I found our conversation so interesting that I finally decided to make a dedicated article about it.
Thanks to pulkomandy who had to dig deeply around it while working on its Caprice Reloaded project, he was able to give me precise details about it. I found our conversation so interesting that I finally decided to make a dedicated article about it.
What RST instruction really is
RST instruction behaves like a CALL, excepted that's a one-byte instruction (versus CALL instruction being 3-bytes length). So it gets faster to execute. This instruction allows to do a CALL uniquely to the following fixed address : &0, &8, &10, &18, &20, &28, &30 and &38. Yeah, it's quite limited..
Be aware that &38 is already used by system interrupts while using IM 1 mode, which is the default interruption mode when the Amstrad CPC gets started. If you want to avoid having &38 address used for interrupts, you can avoid this using another interruption mode such as IM 2. Other addresses are free for your own usage when system interrupts gets disabled.
So basically.. being a faster instruction than CALL, it's possible to put some very special tiny code at the previously specified addresses.
Be aware that &38 is already used by system interrupts while using IM 1 mode, which is the default interruption mode when the Amstrad CPC gets started. If you want to avoid having &38 address used for interrupts, you can avoid this using another interruption mode such as IM 2. Other addresses are free for your own usage when system interrupts gets disabled.
So basically.. being a faster instruction than CALL, it's possible to put some very special tiny code at the previously specified addresses.
Which usage ?
Yeah, good question. I can't answer which specific usage could be done about that... probably a context where a programmer would need uber-extra optimizations where there is a need to gain time over the CALL instruction ?
Note : JR instruction is faster to execute than RST... but of course does not behave the same way (JR/JP not being a CALL instruction).
Note : JR instruction is faster to execute than RST... but of course does not behave the same way (JR/JP not being a CALL instruction).
Errr... OK, so why this article ?
Well, this article was written to let you know more about this instruction. The aim was not to give you applications around it, but let you know how it works and what it does. Now that you know its usage, it's up to you to find a context for it... and if you find a valid one, please feel free to contact me and I will be glad to update this article with your own experience :)