I doubt it can be done portably, but are there any solutions out there? I think it could be done by creating an alternate stack and reseting SP,BP, and IP on function entry
Check out my implementation, it illustrates the asm hacking point and is simple:
https://github.com/user1095108/generic/blob/master/coroutine.hpp