title: x86 Assembly End of Linked List
body: <p>Let's assume I have a linked list, where each node holds an integer. I am able to traverse the linked list and get the value of each node; however, I'm not sure how to detect that I have reached end of the linked list. I know that the last node holds a <code>null</code>, so I tried <code>cmp [ebx+ecx*4],0</code> where basically ebx is the stack pointer to the first parameter of the function and ecx is an increment of 1 for each node. The problem is that a node in the linked list can also hold  a value of 0. How are 0 and <code>null</code> distinguished? </p>
  
  <p>UPDATE:</p>
  
  <p>So I tried something like this, but it ends up being an endless loop. </p>
  
  <pre><code>List:
      add eax, [ebx] //add the value at the address of ebx to eax
      lea ebx, [ebx+4] //update the address of ebx to the next field
      cmp ebx, 0 //check if this address is null
      jne List //if so, then stop
  </code></pre>
  
  <p>Is it correct that if I were to use <code>mov ebx, [ebx+4]</code> instead, it would be incorrect because ebx is now holding the value of the second element and not the address?</p>