title: Atmega32 Assembler reversing string
body: <p>I have problem with reversing String stored in FLASH memory in ATMEGA32. I tried to do it in that way but it is not working well. There is infinite loop in a first stage when I try to put it in stack. Maybe someone had that problem before. Thanks in advance for your tips.</p>
  
  <pre><code>LDI R16,LOW(RAMEND) //stack initialisation
  OUT SPL,R16
  LDI R16, HIGH(RAMEND)
  OUT SPH,R16
  
  NAPIS: .DB "Hello world0"
  LDI ZL,LOW(NAPIS*2)
  LDI ZH,LOW(NAPIS*2)
  LPM R1, Z
  
  LOOP:
  LDI R26,'0'
  TOSTACK:
      LDD R11, Z+2
      PUSH R11
      CPSE R11,R26
  JMP TOSTACK
  FROMSTACK:
      POP R11
      STD Z+2, R11
      CPSE R11,R26    
  JMP FROMSTACK
  
  
  JMP LOOP
  </code></pre>
  
  <hr>
  
  <p>Now it seems like that </p>
  
  <pre><code>LDI R16,LOW(RAMEND) 
  OUT SPL,R16
  LDI R16, HIGH(RAMEND)
  OUT SPH,R16
  
  NAPIS: .DB "Hello world0"
  LDI ZL,LOW(NAPIS*2)
  LDI ZH,LOW(NAPIS*2)
  LPM R1, Z
  
  LOOP:
  
  LDI R26,48
  TOSTACK:
      LDD R11, Z+2
      PUSH R11
      CPSE R11,R26
  JMP TOSTACK
  FROMSTACK:
      POP R11
      STD Z+2, R11
      CPSE R11,R26    
  JMP FROMSTACK
  
  
  JMP LOOP
  </code></pre>
  
  <p>There is infinitive loop in first TOSTACK.</p>