title: How can we tell the stack frame is currently empty?
body: <p>Suppose inside a loop I want to pop elements from the stack based on some comparison condition (the function will also push some elements to the stack based on some condition). How to avoid popping an empty stack?</p>
  
  <p>If at the beginning of the function, I do </p>
  
  <pre><code>push    %rbp
  movq %rsp, %rbp
  </code></pre>
  
  <p>And inside the loop, I check if </p>
  
  <pre><code>cmpq %rbp, %rsp
  je emptyStack
  </code></pre>
  
  <p>is it a possible solution?</p>