Question

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.

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

Now it seems like that

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

There is infinitive loop in first TOSTACK.

Était-ce utile?

La solution

I guess that the 0 in "Hello world0" should terminate the string, but it should probably be a binary 0 and not the ASCII code of character 0 (48 decimal).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top