title: How to write self-modifying code in x86 assembly
body: <p>I'm looking at writing a JIT compiler for a hobby virtual machine I've been working on recently. I know a bit of assembly, (I'm mainly a C programmer. I can read most assembly with  reference for opcodes I don't understand, and write some simple programs.) but I'm having a hard time understanding the few examples of self-modifying code I've found online.</p>
  
  <p>This is one such example: <a href="http://asm.sourceforge.net/articles/smc.html" rel="noreferrer">http://asm.sourceforge.net/articles/smc.html</a></p>
  
  <p>The example program provided does about four different modifications when run, none of which are clearly explained. Linux kernel interrupts are used several times, and aren't explained or detailed. (The author moved data into several registers before calling the interrupts. I assume he was passing arguments, but these arguments aren't explained at all, leaving the reader to guess.)</p>
  
  <p>What I'm looking for is the simplest, most straightforward example in code of a self-modifying program. Something that I can look at, and use to understand how self-modifying code in x86 assembly has to be written, and how it works. Are there any resources you can point me to, or any examples you can give that would adequately demonstrate this?</p>
  
  <p>I'm using NASM as my assembler.</p>
  
  <p>EDIT: I'm also running this code on Linux.</p>