Yosmany325
Member level 3
![Member level 3](/styles/images/ranks/dlevel3.gif)
Hello everyone!
I want to know if is possible to obtain the quotient and remaining of integer division in CCS in the same produced code. Let´s see an example of what I want to obtain:
This code is to encode a percent number using fixed point notation, for example an average = 10000 should give ave_intPart = 100 and ave_decPart = 00.
What I need is a way to reduce instruction count and time required to do this without repeating the division operation (I mean, the compiler be so smart to use just one operation [division] and to store the quotient and remainder at provided variables).
For example suposse the compiler generates something like the following
/* C */
ave_intPart = average / 100;
/* Asm generated code */
movlw 100
...
<a lot of instructions>
/* C */
ave_intPart = average % 100;
/* Asm generated code */
movlw 100
...
<a lot of instructions>
and what I need it to do is something like this
/* C */
ave_intPart = average / 100;
/* C */
ave_intPart = average % 100;
/* Asm generated code */
movlw 100
...
< Here use the temp results to populate both variables, i.e. ave_intPart and ave_decPart >
<a lot of instructions>
Thanks in advance for your help. Yosmany
I want to know if is possible to obtain the quotient and remaining of integer division in CCS in the same produced code. Let´s see an example of what I want to obtain:
Code:
unsigned int32 average;
unsigned int8 ave_intPart;
unsigned int8 ave_decPart;
/* The average variable will never be greater than 10000 */
/* Obtain the 'integer' part */
ave_intPart = average / 100;
/* Obtain the 'decimal' part */
ave_decPart = average % 100;
This code is to encode a percent number using fixed point notation, for example an average = 10000 should give ave_intPart = 100 and ave_decPart = 00.
What I need is a way to reduce instruction count and time required to do this without repeating the division operation (I mean, the compiler be so smart to use just one operation [division] and to store the quotient and remainder at provided variables).
For example suposse the compiler generates something like the following
/* C */
ave_intPart = average / 100;
/* Asm generated code */
movlw 100
...
<a lot of instructions>
/* C */
ave_intPart = average % 100;
/* Asm generated code */
movlw 100
...
<a lot of instructions>
and what I need it to do is something like this
/* C */
ave_intPart = average / 100;
/* C */
ave_intPart = average % 100;
/* Asm generated code */
movlw 100
...
< Here use the temp results to populate both variables, i.e. ave_intPart and ave_decPart >
<a lot of instructions>
Thanks in advance for your help. Yosmany