title: reversing string using stack in assembly, program freezes
body: <p>I am trying to write assembly code to reverse a string by passing it to the stack, then pop it back out using a loop.</p>
  
  <p>I get  dlrow oll and then the program freezes. I can't figure out why. How do I fix this?</p>
  
  <pre><code>%include "io.mac"
  .STACK 100H 
  .DATA
  
      string     db 'Hello world'
      stringLen  equ $-string
  
     .CODE
          .STARTUP
  
  
  
  mov ecx, stringLen
  mov edx, ecx ;save string length
  mov eax, string
  mov esi, eax  ; esi points to start of string
  add eax, ecx
  mov edi, eax
  dec edi       ; edi points to end of string
  jz done       ; if string is 0 or 1 characters long, done
  reverseLoop:
  mov  al, [esi] ; load characters
  mov ah,0
  push ax
  inc esi       ; adjusdt pointers
  dec edi
  dec ecx       ; and loop
  jnz reverseLoop
  
  
  done:
  call reverseString
  .EXIT
  
  call reverseString
  
  reverseString:
  enter 0,0 ;save EBP
  
  mov cx, dx
  
  
  Lp1:
  pop ax
  mov ah,0
  PutCh al
  loop Lp1
  
    leave
    ret 8
  </code></pre>