[sdiy] Organisation of tasks in synth's main uP

Tom Wiltshire tom at electricdruid.net
Tue Nov 23 18:31:35 CET 2010


The device header files for the dsPIC (and presumably PIC too, but I haven't checked) make all the bits of the status register available using MCHPs favoured 'struct' approach.

This means the following is legal:

int x = SRbits.OV;

You can also do tests and comparisons with it, or any of the other status register bits:

if (SRbits.OV) {
	// Overflow!

} else {
	// No overflow!
}

I've just tried this, and the compiler throws no error. YPMV (Your platform may vary?).

T.


On 23 Nov 2010, at 16:50, Noah Vawter wrote:

> 
> pro-question time: in assembly, I rely heavily on the overflow bit being set to detect wrap-around, e.g. in 8-bit registers.  But these days I program mainly in C and I can't figure out how to access that overflow bit.
> I have gone so far as to use 7-bit numbers and treat the MSB as an overflow, but does anyone know how to read the CPU's overflow bit from C?
> 
> thank you,
> -N
> 
> 
> On Nov 23, 2010, at 8:54 AM, Olivier Gillet wrote:
> 
>>> Most compilers aimed at embedded systems, including GCC, usually have
>>> some way to place native assembler instructions in your C code
>>> ("inline assembler") and have the compiler sort out all the other
>>> stuff (function prologue and epilogue, etc) for you.  However  I don't
>>> generally recommend it for large functions (it tends to block any
>>> optimisations in that function, same with longjmp/setjmp) so best to
>>> hide it away in utility functions.
>> 
>> Same experience here... I found that avr-gcc did the "right" register
>> allocation in code surrounding inlined assembly only when the assembly
>> code was kept small and didn't touch too many variables. So it seems
>> better (and also good from a readability and code reuse point of view)
>> to keep in C the "glue" between small inlined assembly functions.
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at dropmix.xs4all.nl
>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>> 
> 
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy




More information about the Synth-diy mailing list