How small can code get ?

My first posting here, i knew or barely understood much. I started with http://forum.arduino.cc/index.php?topic=163846.msg1223626#msg1223626 and got this down to a finite

{
  unsigned char temp;

  DDRD = 0x01;			// PD0 as output
  ACSR = 0x00; 			// ACSR Configured

  while(1)
  {
    temp = ACSR;		// ACSR --> temp
    temp &= 0x20;		// Isolate ACO 

    if(temp & 0x20)		// Test if ACO is set
      PORTD &= ~0x01;	        // ACO = 1 , PD0 = HIGH
    else                        // ELSE
      PORTD |= 0x01;	        // ACO = 0 , PD0 = LOW
  }

This is just a small part of a larger system, this piece has come from 3kb when i started & now is done in 190bytes, my questions are;
Can code be compacted any further than this? If so, would that be assembly?
Does disabling the ADC, allow for a greater amount of inputs for the comparator?

Can code be compacted any further than this? If so, would that be assembly?

The stuff you posted will be pretty much 1:1 with assembler. Those are very basic operations.

Good, i like that answer :smiley:

    else                        // ELSE

Good descriptive comments as well :)


Rob

    temp = ACSR;      // ACSR --> temp
    temp &= 0x20;     // Isolate ACO 
    if(temp & 0x20)       // Test if ACO is set

You don't need both of these bitwise-AND operations. Hopefully the compiler is smart enough to know that but just in case you should change it to:

    temp = ACSR;      // ACSR --> temp
    temp &= 0x20;     // Isolate ACO 
    if(temp)      // Test if ACO is set

If you don't need to check that one bit more than once (can't tell without seeing the rest of the code) you can probably save time by not saving a copy of that bit in a variable:

    temp = ACSR;      // ACSR --> temp
    if(temp & 0x20)       // Test if ACO is set

And if you don't need to test the flag multiple times, no need to use a temporary variable at all:

    if(ACSR & 0x20)       // Test if ACO is set

That might save a few instructions.