title: Switch Case Assembly Language
body: <p>I am looking at the assembly language code of a switch statement.</p>
  
  <p>I understand how the code works and what the cases are. My question is how do I decide on the case names? </p>
  
  <p>Below is the assembly language code, which will be followed with my interpretation of it. I basically just need to use the jump table and fill in the case names.</p>
  
  <pre><code>    1 8048420: push %ebp
      2 8048421: mov %esp, $ebp
      3 8048423: mov 0x8(%ebp), %eax       // x
      4 8048426: mov 0xc(%ebp), %edx       // n
      5 8048429: sub $0x32, %edx           // so least value of case is 32
      6 804842c: cmp $0x5, %edx            // max value is 37
      7 804842f: ja 8048448 &lt;switch+0x28&gt;  // if &gt;37, go to default
      8 8048431: jmp *0x80485d0(, %edx, 4)  //THIS RIGHT HERE ?
      9 8048438: shl $0x2, %eax             // CASE A
     10 804843b: jmp 804844b &lt;switch+0x2b&gt;  //break;
     11 804843d: sar $0x2, %eax             //CASE B
     12 8048440: jmp 804844b &lt;switch+0x2b&gt;  //break
     13 8048442: lea (%eax, %eax, 2), %eax  //CASE C
     14 8048445: imul %eax, %eax     
     15 8048448: add $0xa, %eax             //fall through to default
     16 804844b: pop %ebp                   //return
     17 804844c: ret
  </code></pre>
  
  <p>The jump table that the gdb command creates:
  I am doing x/6w 0x80485d0 </p>
  
  <pre><code>0x80485d0: 0x08048438 0x08048448 0x08048438 0x0804843d
  0x80485e0: 0x08048442 0x08048445
  </code></pre>
  
  <p>My interpretation:</p>
  
  <pre><code>int result = x;
  switch(n) {
  case __:
      x = x &lt;&lt; 2;
      break;  
  case __:
      x = x &gt;&gt; 2
      break;
  case __:
      x = 4*x;
      x = x*x
  case __: //default
      x += 0xa 
  return x;
  }
  </code></pre>
  
  <p>I just don't understand how to look up the jump table and decide which values of n between 32 and 37 fit in which of the case blanks.</p>
  
  <p>Any help would be appreciated.
  Thank you.</p>