title: Recursion in assembly?
body: <p>I'm trying to get a better grasp of assembly, and I am a little confused about how to recursively call functions when I have to deal with registers, popping/pushing, etc.</p>
  
  <p>I am embedding x86 assembly in C++.  Here I am trying to make a method which given an array of integers will build a linked list containing these integers in the order they appear in the array.  </p>
  
  <p>I am doing this by calling a recursive function:</p>
  
  <pre><code>insertElem (struct elem *head, struct elem *newElem, int data) 
  </code></pre>
  
  <p>-head: head of the list</p>
  
  <p>-data: the number that will be inserted at the end of a list</p>
  
  <p>-newElem: points to the location in memory where I will store the new element (data field)</p>
  
  <p>My problem is that I keep overwriting the registers instead of a typical linked list.
  For example, if I give it an array {2,3,1,8,3,9} my linked-list will return the first element (head) and only the last element, because the elements keep overwriting each other after head is no longer null.</p>
  
  <p>So here my linked list looks something like:
  2-->9    instead of 2-->3-->1-->8-->3-->9</p>
  
  <p>I feel like I don't have a grasp on how to organize and handle the registers.  newElem is in EBX and just keeps getting rewritten.  Thanks in advance!</p>