Jump to content
Sign in to follow this  
onyx

Boostc: Error In Multiply Code Generation

Recommended Posts

Bug description:

multiply by 256 generates wrong results

 

Steps to reproduce:

compile the following with BoostC

#include <system.h>

char h, l;
unsigned int gamma;

void main()
{
 l = 0xE8;       // low byte of gamma
 h = 0x03;       // hi byte of gamma

 gamma = h*256 + l;             // *** wrong, due to shift optimization ?;-)
 
 gamma = ((int) h) << 8 | l;    // *** correct     gamma = 1000
}

 

produces the following code

 ...
 
 gamma = h*256 + l;             // *** wrong, due to shift optimization ?;-)
1FE5          ; {
1FE5   A501            CLRF CompTempVar7
1FE6   A401            CLRF CompTempVar6
1FE7   2108            MOVF gbl_l, W
1FE8   2407            ADDWF CompTempVar6, W
1FE9   A600            MOVWF CompTempVar8
1FEA   2508            MOVF CompTempVar7, W
1FEB   A700            MOVWF CompTempVar9
1FEC   0318            BTFSC STATUS,C
1FED           
1FED   A70A            INCF CompTempVar9
1FEE           
1FEE           
1FEE   2608            MOVF CompTempVar8, W
1FEF   A200            MOVWF gbl_gamma
1FF0   2708            MOVF CompTempVar9, W
1FF1   A300            MOVWF gbl_gamma+D'1'
1FF2          ; }

 
 gamma = ((int) h) << 8 | l;                              
1FF2          ; {
1FF2   A401            CLRF CompTempVar10
1FF3   2008            MOVF gbl_h, W
1FF4   A500            MOVWF CompTempVar11
1FF5   2108            MOVF gbl_l, W
1FF6   2404            IORWF CompTempVar10, W
1FF7   A600            MOVWF CompTempVar12
1FF8   2508            MOVF CompTempVar11, W
1FF9   A700            MOVWF CompTempVar13
1FFA   2608            MOVF CompTempVar12, W
1FFB   A200            MOVWF gbl_gamma
1FFC   2708            MOVF CompTempVar13, W
1FFD   A300            MOVWF gbl_gamma+D'1'
1FFE          ; }

 

Expected behaviour:

the compiler should generate correct code so that gamma evaluates to 1000

 

Is the problem 100% reproduceable: yes

 

IDE version: SourceBoost IDE 5.6.1

Compiler: BoostC

Compiler version: Alpha 1.3

 

OS: Win2000

 

Comments:

Share this post


Link to post
Share on other sites

You are right. Error was in left shift code generation. Now fixed in BoostC 1.4 Alpha release.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji 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...
Sign in to follow this  

×
×
  • Create New...