I made an implementation many years ago for the HP 49G+. You can find the C code here
https://github.com/modlfo/quinehp
Unfortunately, it's not well documented and I don't remember all the stuff I did back then.
I hope it can help you.
Leonardo
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)