Speed and Efficiency Testing

Working with Control Flags
6/12/2009 1:40:00 PM

It is desirable to write code that is fast and efficient rather then elegant but bloated. The PIC18 has several bit-oriented instructions which make working with bits very efficient. The PIC32 does not have any bit-oriented instructions.

The code for the PIC18 defines a data memory location and uses the individual bits as control flags as follows:
code sniplet 1 With the PIC32 a typedef controlWord was created and the variable Control was declared of type controlWord as follows
code sniplet 2 The disassembly listing clearly shows the inefficient code that is produced when working with bits. Even though the PC32 is running twice as fast as the PIC18, the PIC18 will set, clear and test bits faster. Since the PIC32 has more data memory than is required by my application, let's see what happens if I use an entire byte as a control flag as follows:
code sniplet 3 From this I would conclude that it is more efficient to use an entire byte as a control flag with a PIC32 microcontroller rather than using a single bit.


Development Tools

  • Visual Studio 2005
  •   .NET Framework 2.0
  •   Visual C# 2005
  •   Visual Basic 2005
  •   SQL Server 2005
  •   C32 C Compiler
  •   MPASM Assembler