Jump to content
jartim

Same source code generates different and incorrect code in some places

Recommended Posts

jartim    0

Bug description:

The same source code line generates different assembly code in different places. Sometimes the generated code is incorrect, sometimes it is correct.

Steps to reproduce:

Use the same source code in 2 different places in the source.

Detailed description to reproduce this problem I use this statement in two different places in my source code -

WatchdogTarget = CONST_WDT_MINTIME + (Trembler & 0x07);

CONST_WDT_MINTIME is a constant -

#define CONST_WDT_MINTIME 1U

The first time it is used, the following code is generated (which looks correct) -

01D7  3007     MOVLW 0x7
01D8  0547     ANDWF 0x47, W
01D9  00CA     MOVWF 0x4A
01DA  0A4A     INCF 0x4A, W
01DB  00C4     MOVWF WatchdogTarget

The second time is it used, the following code is generated (which is not correct as it modifies the value in "Trembler" at 0x47) -

020A  3007     MOVLW 0x7
020B  05C7     ANDWF 0x47, F
020C  0A47     INCF 0x47, W
020D  00C4     MOVWF WatchdogTarget

Expected behaviour:

This is the code I would expect to see -

020A  3007     MOVLW 0x7
020B  05C7     ANDWF 0x47, W
020C  0A47     ADDLW 0x01
020D  00C4     MOVWF WatchdogTarget

The compiler should not modify the value of "Trembler" at 0x47 (and as the value of CONST_WDT_MINTIME may be other values at compile-time)

If CONST_WDT_MINTIME was (say) 32, I would expect to see this instead -

020A  3007     MOVLW 0x7
020B  05C7     ANDWF 0x47, W
020C  0A47     ADDLW 0x20
020D  00C4     MOVWF WatchdogTarget

Is the problem 100% reproduceable: Every time

IDE version:  MPLAB-X 4.0

Compiler:       BoostC++

Compiler version:  7.42

Target device: PIC12F635

OS:                    Windows 7 64-bit

 

Share this post


Link to post
Share on other sites
Reynard    0

Hi jartim,

Are you sure INCF 0x47, W modifies the value in Trembler ?

Cheers

Reynard

 

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×