Jump to content

Recommended Posts

Hi

 

I have the following function compiled for a pic18F6520:

UINT16_T AdcMicrophoneConvert(VOID_T)

{

UINT16_T ret;

 

// we can assume that the AD is already set to microphone channel..

// and has completed a conversion

 

ret = adresh << 8;

ret += adresl;

ad_go_done = 1; // start the next conversion.

 

return ret;

}

it compiles:

 

AdcMicroph_0001D

{ AdcMicrophoneConvert ; function begin

MOVLB 0x03

CLRF CompTempVar490, 1

MOVF gbl_adresh, W

MOVWF CompTempVar491, 1

MOVF CompTempVar490, W, 1

MOVWF AdcMicroph_0001D_1_ret, 1

MOVF CompTempVar491, W, 1

MOVWF AdcMicroph_0001D_1_ret+D'1', 1

MOVF gbl_adresl, W

ADDWF AdcMicroph_0001D_1_ret, F, 1

BTFSC STATUS,C

INCF AdcMicroph_0001D_1_ret+D'1', F, 1

BSF gbl_ad_go_done,1

MOVF AdcMicroph_0001D_1_ret, W, 1

MOVWF CompTempVarRet489, 1

MOVF AdcMicroph_0001D_1_ret+D'1', W, 1

MOVWF CompTempVarRet489+D'1', 1

RETURN

} AdcMicrophoneConvert function end

 

shouldn't the optimzer just reduce this to five lines of code, i.e. read two registers and store then set the start convert bit.

 

I tried changing the ret += adresl to ret = adresl but thids actually increases the code space.

 

is there a reason why this is happening?

 

regards

rob carter

Share this post


Link to post
Share on other sites

Hi Rob,

 

I suppose the compiler thinks you are doing some 16 bit arithmetic.

 

Try using this macro or even a union for ret to make it look like a 2 byte array.

 

	MAKESHORT(ret, adresh,adresl);

 

The compiler can only make so may asumptions.

 

Cheers

 

Reynard

 

Before anyone spots it try this:

 

   MAKESHORT(ret, adresl,adresh);

Edited by Reynard

Share this post


Link to post
Share on other sites

hi thanks, I hadn't spotted those macro's

 

one other question, if you can help, is there a way to see what has been removed by the optimizer at compile /link time?

 

rob

Share this post


Link to post
Share on other sites
one other question, if you can help, is there a way to see what has been removed by the optimizer at compile /link time?

 

There is no built-in functionality to display optimised out code. One way is to compile your code using different optimisation flags (i.e. -O1 and -O2) and compare results.

 

 

Regards,

Pavel

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

×