Leave it as an exercise to the reader.

I had to implement exec() on Unix V6 for my OS course at uni.