title: x86 assembly language homework prob
body: <p>I need help with a homework problem. I am supposed to figure out what the value of <code>edx</code> will be after this code runs.</p>
  
  <pre><code>0x40106e    &lt;main+30&gt;:      mov    $0x1,%edx
  0x401073    &lt;main+35&gt;:      mov    $0x8,%ecx
  0x401078    &lt;main+40&gt;:      test   %ecx,%ecx
  0x40107a    &lt;main+42&gt;:      jg     0x40107e &lt;main+46&gt;
  0x40107c    &lt;main+44&gt;:      jmp    0x40108a &lt;main+58&gt;
  0x40107e    &lt;main+46&gt;:      lea    (%ecx,%ecx,1),%eax
  0x401081    &lt;main+49&gt;:      lea    (%eax,%edx,1),%eax
  0x401084    &lt;main+52&gt;:      lea    0xffffffff(%eax),%edx
  0x401087    &lt;main+55&gt;:      dec    %ecx
  0x401088    &lt;main+56&gt;:      jmp    0x401078 &lt;main+40&gt;
  0x40108a    &lt;main+58&gt;:      // endpoint
  </code></pre>
  
  <p>Since it is homework I don't really want to know the answer as much as how to figure it out. I was having trouble with figuring out the loop, but I think I got it. I think the <code>test %ecx,%ecx</code> loops until <code>%ecx</code> is decremented to 0. Is that right? What's really getting me is all the <code>lea</code> stuff. I cannot figure out what that is doing.</p>