Jump to content
Sign in to follow this  
Guest Chris

Wrong code generation for ? operator

Recommended Posts

Guest Chris

BoostC Version 7.43 generates wrong code for ? operator with PIC18F6622.

Working code using if statements from CASM file:

 

unsigned int d = accel_axis_raw.AXIS_X / BSCALEX;
if (d > 90) bmotion->OutX = 90 + 127; else bmotion->OutX = d + 127;
3050  0E5A      	MOVLW 0x5A
3052  659F      	CPFSGT ACCEL_Getb_0006F_14_d, 1
3054  67A0      	TSTFSZ ACCEL_Getb_0006F_14_d+D'1', 1
3056  D001      	BRA	label223
3058  D007      	BRA	label224
305A            label223
305A  519C      	MOVF ACCEL_Getb_0006F_arg_bmotion+D'1', W, 1
305C  6EEA      	MOVWF FSR0H
305E  519B      	MOVF ACCEL_Getb_0006F_arg_bmotion, W, 1
3060  6EE9      	MOVWF FSR0L
3062  0ED9      	MOVLW 0xD9
3064  6EEF      	MOVWF INDF0
3066  D09D      	BRA	label236
3068            label224
3068  0E7F      	MOVLW 0x7F
306A  259F      	ADDWF ACCEL_Getb_0006F_14_d, W, 1
306C  6FA1      	MOVWF CompTempVar3286, 1
306E  519C      	MOVF ACCEL_Getb_0006F_arg_bmotion+D'1', W, 1
3070  6EEA      	MOVWF FSR0H
3072  519B      	MOVF ACCEL_Getb_0006F_arg_bmotion, W, 1
3074  6EE9      	MOVWF FSR0L
3076  51A1      	MOVF CompTempVar3286, W, 1
3078  6EEF      	MOVWF INDF0

Bad code using ? : operator:

unsigned int d = accel_axis_raw.AXIS_X / BSCALEX;
bmotion->OutX = 127 + (d > 90 ? 90 : d);
3050  0E5A      	MOVLW 0x5A
3052  659F      	CPFSGT ACCEL_Getb_0006F_14_d, 1
3054  67A0      	TSTFSZ ACCEL_Getb_0006F_14_d+D'1', 1
3056  D001      	BRA	label223
3058  D003      	BRA	label224
305A            label223
305A  0E5A      	MOVLW 0x5A
305C  6FA2      	MOVWF CompTempVar3287, 1
305E  D002      	BRA	label225
3060            label224
3060  519F      	MOVF ACCEL_Getb_0006F_14_d, W, 1
3062  6FA2      	MOVWF CompTempVar3287, 1
3064            label225
3064  51A2      	MOVF CompTempVar3287, W, 1
3066  0F7F      	ADDLW 0x7F
3068  6FA1      	MOVWF CompTempVar3286, 1
306A  519C      	MOVF ACCEL_Getb_0006F_arg_bmotion+D'1', W, 1
306C  6EEA      	MOVWF FSR0H
306E  519B      	MOVF ACCEL_Getb_0006F_arg_bmotion, W, 1
3070  6EE9      	MOVWF FSR0L
3072  51A1      	MOVF CompTempVar3286, W, 1
3074  6EEF      	MOVWF INDF0

 

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