avr: appending a character to a string does not work.
Original Reporter info from Mantis: georghieber
-
Reporter name: Georg Hieber
Original Reporter info from Mantis: georghieber
- Reporter name: Georg Hieber
Description:
Given
var
c: char;
st: string[63];
…
c:= Serial0.Getchar;
st := st + c;
translates to (only the string concatenation):
# [64] then st := st + c;
lds r19,(U_sPsTESTBED_ss_C)
lsl r19
lsl r19
lsl r19
lsl r19
lsl r19
lsl r19
lsl r19
lsl r19
ori r19,1
mov r18,r1
ldi r30,lo8(+258)
ldi r31,hi8(+258)
add r30,r28
adc r31,r29
st Z+,r19
st Z,r18
ldi r18,lo8(+258)
ldi r19,hi8(+258)
add r18,r28
adc r19,r29
ldi r20,lo8(U_sPsTESTBED_ss_ST)
ldi r21,hi8(U_sPsTESTBED_ss_ST)
ldi r26,-1
mov r22,r26
mov r23,r1
ldi r24,lo8(+2)
ldi r25,hi8(+2)
add r24,r28
adc r25,r29
call fpc_shortstr_concat
ldi r20,lo8(+2)
ldi r21,hi8(+2)
add r20,r28
adc r21,r29
ldi r24,lo8(U_sPsTESTBED_ss_ST)
ldi r25,hi8(U_sPsTESTBED_ss_ST)
ldi r26,63
mov r22,r26
mov r23,r1
call fpc_shortstr_to_shortstr
So, the character is loaded into r19, shifted out into nirvana, the now cleared r19 set to 1 and stored in the length byte of a temporary string on the stack, and a value of 0 in the [1] byte of that string, which is thereafter passed to the shortstring concatenation routine. The rest seems to work, the code snippet is inside a loop, and with each received character st grows one byte in length – filled with #0.
Additional information:
There is a workaround. Assigning a character to a shortstring works.:
var
c: char;
st: string[63];
st1: string[1];
…
c:= Serial0.Getchar;
st1 := c;
st := st + c;
Mantis conversion info:
- Mantis ID: 32072
- OS: embedded
- Platform: avr
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 37585 (#f22a6629)