Ah, the old Intel 8051. It was the first CPU I developed a debugger for and it brings back great memories. Writing a compiler for any CPU is similar to any other CPU. While I haven't written one, the two books I can highly recommend are "Compilers: Principles, Techniques and Tools" by Alfred V. Aho, Ravi Sethi and Jeffrey D. Ullman and "Compiler Design in C" by Allen Holub.
This was first published in August 2002