Topic : Compiler uses the Y register without initializing it

Forum : ST7/STM8

Original Post
Post Information Post
September 3, 2009 - 4:58pm
Guest

I've encountered an issue where the compiler uses the Y register as in index but never actually initializes it. Below is the listing for a stripped down function that reproduces the error.

----------START OF LISTING----------

RCSTM8 COMPILER V2.22.09.203, C_FILE1 09/03/09 16:51:25

QCW(0x00183F20)

RCSTM8 COMPILER V2.22.09.203, COMPILATION OF MODULE C_FILE1
OBJECT MODULE PLACED IN C:\Documents and Settings\blasio muscat\Desktop\Test2\C File1.obj
COMPILER INVOKED BY: QUIET GENERATEDEPFILE CODE DB OJ(C:\Documents and Settings\blasio muscat\Desktop\Test2\C File1.obj) PR(C:\Documents and Settings\blasio muscat\Desktop\Test2\C File1.lst) PIN(C:\Program Files\Raisonance\Ride\Inc;C:\Program Files\Raisonance\Ride\Inc\ST7) ST7 DGC(DATA) DLC(PAGE0) O(3,SIZE) NOINITSTATICVAR SMALLOBJECT ET(INT)

stmt level source
1 unsigned short NOVX_Decay_P[6], NOVX_Decay_N[6];
2
3 #define MAX_RX_BYTES 17
4 static unsigned char RxBuf[MAX_RX_BYTES];
5
6 void ParseDecayData(void)
7 {
8 1 unsigned char idx = RxBuf[0]*3;
9 1 unsigned char c = 0;
10 1 unsigned short t;
11 1
12 1 t = *(unsigned short*)(RxBuf+2);
13 1 c |= (NOVX_Decay_P[ idx ] != t);
14 1 NOVX_Decay_P[ idx ] = t;
15 1
16 1 }
17
RCSTM8 COMPILER V2.22.09.203
ASSEMBLY LISTING OF GENERATED OBJECT CODE

; FUNCTION ParseDecayData (BEGIN)
; Y is assigned to idx
; SOURCE LINE # 8
0000 C60000 F LD A,RxBuf
0003 AE03 LD X,#003H
0005 42 MUL X,A
0006 97 LD X,A
; BH is assigned to c
; CX is assigned to t
; SOURCE LINE # 12
0007 C60000 F LD A,RxBuf + 02H
000A B705 F LD ?CH,A
000C C60000 F LD A,RxBuf + 03H
000F B706 F LD ?CL,A
; SOURCE LINE # 13
0011 58 SLL X
0012 D10001 F CP A,(NOVX_Decay_P + 01H,X)
0015 2605 JRNE ?LAB_0004
0017 B605 F LD A,?CH
0019 D10000 F CP A,(NOVX_Decay_P + 00H,X)
001C ?LAB_0004:
; SOURCE LINE # 14
001C 909F LD A,Y
001E 48 SLL A
001F 97 LD X,A
0020 B605 F LD A,?CH
0022 D70000 F LD (NOVX_Decay_P + 00H,X),A
0025 B606 F LD A,?CL
0027 D70001 F LD (NOVX_Decay_P + 01H,X),A
002A 81 RET
; idx unsigned char (size=1). Automatic variable in PAGE0
; c unsigned char (size=1). Automatic variable in PAGE0
; t unsigned short (size=2-Alg). Automatic variable in PAGE0

; FUNCTION ParseDecayData (END)

RCSTM8 COMPILER V2.22.09.203

MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 43 ----
CONSTANT SIZE = ---- ----
DATA SIZE = 41 ----
PAGE0 SIZE = ---- 4
BIT SIZE = ---- ----
END OF MODULE INFORMATION.

RCSTM8 COMPILATION COMPLETE. 0 WARNING, 0 ERROR

Replies
Post Information Post
+1
0
-1
September 4, 2009 - 9:42am
Raisonance Support Team

Hi Blasio,

Thanks for this detailed report. We reproduced the problem in our Labs.
The problem is caused by an over-optimization in the O(3) and will be fixed in the next RKit-STM8 release.

Until the fixed compiler is available, you can switch the optimization to level 2 for the function that causes the problem in the following way (in your C source code):

#pragma save      // Save the current compiler state (including optimization level)
#pragma O(2)      // Set optimization level 2

void ParseDecayData(void)
{
    ... // Your function code here
}
#pragma restore   // Restore previous compiler state (original optimization level)

This way the compiler will reduce the optimization level just on the sensitive function.

Let us know if you still have some issues on this.

Regards,
Bruno

+1
0
-1
September 4, 2009 - 10:55am
Guest

This solves the issue for me.

Thanks,
Blasio