Jump to content
Reynard

Long Winded Assembler Code

Recommended Posts

Here z is a long and a constant (126) is being shifted left by 23 bits.

 

The result should be a simple assignment z = 0x7e000000 computed by the compiler.

 

Why all those extra instructions ?

 

		z = (long)126 << 23;
0D6E  0E7E		  MOVLW 0x7E
0D70  6E44		  MOVWF log_00000_1_z+D'2'
0D72  6A45		  CLRF log_00000_1_z+D'3'
0D74  6A48		  CLRF CompTempVar664+D'2'
0D76  6A49		  CLRF CompTempVar664+D'3'
0D78  6A42		  CLRF log_00000_1_z
0D7A  6A43		  CLRF log_00000_1_z+D'1'
0D7C  3644		  RLCF log_00000_1_z+D'2', F
0D7E  3645		  RLCF log_00000_1_z+D'3', F
0D80  3644		  RLCF log_00000_1_z+D'2', F
0D82  3645		  RLCF log_00000_1_z+D'3', F
0D84  3644		  RLCF log_00000_1_z+D'2', F
0D86  3645		  RLCF log_00000_1_z+D'3', F
0D88  3644		  RLCF log_00000_1_z+D'2', F
0D8A  3645		  RLCF log_00000_1_z+D'3', F
0D8C  3644		  RLCF log_00000_1_z+D'2', F
0D8E  3645		  RLCF log_00000_1_z+D'3', F
0D90  3644		  RLCF log_00000_1_z+D'2', F
0D92  3645		  RLCF log_00000_1_z+D'3', F
0D94  3644		  RLCF log_00000_1_z+D'2', F
0D96  3645		  RLCF log_00000_1_z+D'3', F
0D98  0E80		  MOVLW 0x80
0D9A  1644		  ANDWF log_00000_1_z+D'2', F

 

BoostC 6.90, XP Pro SP3, PIC 18F8722

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

The extra code is caused by the type cast operation. Constant 126 is converted into long what involves creation of a temporary variable and copying constant value into it and than this temporary variable gets shifted. To get rid of these instructions just remove type cast:

 

z = 126 << 23;

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

That's bad news. As a constant the compiler should have done all the shifting not the PIC.

 

Both MikroC and Hi-Tech C do the expected simple assignment.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
That's bad news. As a constant the compiler should have done all the shifting not the PIC.

 

Both MikroC and Hi-Tech C do the expected simple assignment.

 

We have added a fix for this into our todo list. Will likely to get fixed by the next release.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Thanks Pavel. Look forward to squeezing out these little quirks.

 

Will work around it for now.

 

Cheers

 

Reynard

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...

×
×
  • Create New...