The book Programming for the Java Virtual Machine explains the JVM instruction set and how to write code for it. It also introduces a bytecode assembler called Oolong, which I have not been able to download. You can, however, use Jasmin, the predecessor of Oolong. Essentially, you write a text file with instructions and Jasmin will spit out a .class file. The book was published in 1999, but it is still a good and gentle introduction to the VM.