title: Assembly infinite loop (jmp -2)
body: <p>I heard that with a jmp -2 we could make an infinite loop. It sounded weird but after the explanation that a relative jump would take one byte, the next instruction address (eip) would be 2 bytes less than the jmp address. So, I decided to implement that but I can't make it work.<br>
  That's my source code:</p>
  
  <pre><code>SECTION .text
  
  global main
  main:
     push   ebp
     mov    esp, ebp
     jmp    0x-2
     leave
     ret
  </code></pre>
  
  <p>And used this to compile:
  <pre><code>nasm -f elf asmloop.asm -o objasmloop.o </pre></code></p>
  
  <p><pre><code> ld -m elf_i386 -o execasmloop -e main objasmloop.o  </pre></code></p>
  
  <p>I also tried to use the hex value of -2 (FE) but still get segmentation fault.
  After all, I took a look at the disassembly with GDB:</p>
  
  <pre><code>Dump of assembler code for function main:
     0x08048060 &lt;+0&gt;: push   %ebp
     0x08048061 &lt;+1&gt;: mov    %ebp,%esp
     0x08048063 &lt;+3&gt;: jmp    0xfffffffe
     0x08048068 &lt;+8&gt;: leave  
     0x08048069 &lt;+9&gt;: ret  
  </code></pre>
  
  <p>I was able to see on this dump that the actual difference between jmp address and leave address is in fact 5 bytes (it's not using the short reference jmp). But I tried with this to and the result was the same (segmentation fault). How can I perform that kind of infinite-loop?</p>