title: imul using DWORD PTR [reg+reg*n-n]
body: <p>I clearly don't understand what exactly is happening with this imul because when I do the calculations myself it does not come out as 2. If anyone could explain the r/m form and why imul is getting 2 I'd greatly appreciate it.</p>
  
  <p>Both esi and ebx = 0x1.
  The *4 is in reference to the word size, correct? (4 is DWORD I think)?
  The last part, -0x4, is the displacement? Just for adding or subtracting from the value?</p>
  
  <p>By the way, when I do the calculations myself I get -2 if you didn't already guess.</p>
  
  <pre><code>9: x/32xw $esp
  0xffffd300: 0xffffd3f4  0x00000000  0xffffd338  0x08049226
  0xffffd310: 0x00000001  0x00000002  0x00000006  0x00000001
  0xffffd320: 0x00000002  0x00000006  0xffffd358  0x08048a83
  0xffffd330: 0x0804b6d0  0x08049620  0xffffd358  0x08048a7a
  8: /x $ebp = 0xffffd328
  7: /x $ebx = 0x1
  6: /x $ecx = 0x0
  5: /x $edx = 0x0
  4: /x $edi = 0x0
  3: /x $esi = 0xffffd310
  2: /x $eax = 0x2
  1: x/10i $eip
  =&gt; 0x8048b79 &lt;phase_2+49&gt;:  imul   eax,DWORD PTR [esi+ebx*4-0x4]
     0x8048b7e &lt;phase_2+54&gt;:  cmp    DWORD PTR [esi+ebx*4],eax
  
  (gdb) 
  0x08048b7e in phase_2 ()
  9: x/32xw $esp
  0xffffd300: 0xffffd3f4  0x00000000  0xffffd338  0x08049226
  0xffffd310: 0x00000001  0x00000002  0x00000006  0x00000001
  0xffffd320: 0x00000002  0x00000006  0xffffd358  0x08048a83
  0xffffd330: 0x0804b6d0  0x08049620  0xffffd358  0x08048a7a
  8: /x $ebp = 0xffffd328
  7: /x $ebx = 0x1
  6: /x $ecx = 0x0
  5: /x $edx = 0x0
  4: /x $edi = 0x0
  3: /x $esi = 0xffffd310
  2: /x $eax = 0x2
  1: x/10i $eip
  =&gt; 0x8048b7e &lt;phase_2+54&gt;:  cmp    DWORD PTR [esi+ebx*4],eax
     0x8048b81 &lt;phase_2+57&gt;:  je     0x8048b88 &lt;phase_2+64&gt;
  </code></pre>