title: ENTER and LEAVE in Assembly?
body: <p>I was reading <em>The Art of Assembly Language</em> (Randall Hyde, <a href="https://rads.stackoverflow.com/amzn/click/com/1593272073" rel="noreferrer" rel="nofollow noreferrer">link to Amazon</a>) and I tried out a console application in that book. It was a program that created a new console for itself using Win32 API functions. The program contains a procedure called <code>LENSTR</code>, which stores the length of string in the <code>EBP</code> register. The code for this function is as follows:</p>
  
  <pre><code>LENSTR PROC
  ENTER 0, 0
  PUSH  EAX
  ;----------------------
  CLD
  MOV   EDI, DWORD PTR [EBP+08H]
  MOV   EBX, EDI
  MOV   ECX, 100 ; Limit the string length
  XOR   AL, AL
  REPNE SCASB ; Find the 0 character
  SUB   EDI, EBX ; String length including 0
  MOV   EBX, EDI
  
  DEC   EBX
  ;----------------------
  POP   EAX
  LEAVE
  RET   4
  LENSTR ENDP
  </code></pre>
  
  <p>Could you explain the usage of the <code>enter</code> and <code>leave</code> commands here?</p>