#define ENHI() PORTx |= (1<<EN) becomes SBI in disass

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From Bob Gardner in thread
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=41558

Quote:

One more step:

#define LCD_EN_BIT_NUM 0
#define LCD_RS_BIT_NUM 1

#define LCD_EN (1<<LCD_EN_BIT_NUM)
#define LCD_RS (1<<LCD_RS_BIT_NUM)

#define ENHI() PORTC |=  LCD_EN
#define ENLO() PORTC &= ~LCD_EN
#define ENPULSE() ENHI(); ENLO()

//usage
  PORTD=data;
  ENPULSE();


I started a new thread because this is OT from the OP in that thread, and think it is more a GCC thing.

I was always concerned with codespace and instructions required with this method. I wasn't sure if the compiler would figgure out to just set or clear that one bit, or if it would actually read the port change the one bit and write the port. So I tried it out and read the dissasembler...

#include 

#define EN     PA7   // Strobe, latch data
#define LCD_EN (1<<EN)
#define CTRL_PORT  PORTA
#define ENHI() CTRL_PORT |=  LCD_EN
#define ENLO() CTRL_PORT &= ~LCD_EN
#define ENPULSE() ENHI(); ENLO()

int main( void )
{
//usage
   DDRC = 0xFF;
   ENPULSE(); 
}

Generated this:

17:         ENPULSE(); 
+0000006B:   9AAF        SBI     0x15,7           Set bit in I/O register
+0000006C:   98AF        CBI     0x15,7           Clear bit in I/O register

That I like, quick and much more atomic than what I get when I use it in the rest of my program. The exact same #defines were used and for some reason it no longer makes use of the CBI instruction.

60:          ENPULSE();
+0000033F:   9ADF        SBI     0x1B,7           Set bit in I/O register
+00000340:   E71F        LDI     R17,0x7F         Load immediate
+00000341:   B38B        IN      R24,0x1B         In from I/O location
+00000342:   2381        AND     R24,R17          Logical AND
+00000343:   BB8B        OUT     0x1B,R24         Out to I/O location

I could post all the reast of the code in the project, but that would take much space.

Both are compiled at -Os, I have the latest WinAVR and Studio

What is causing this change?

Is there any good way to tell it just to clear the bit, from C, using good programing practice? It would save 3 instructions each time, not that I need more speed or that I'm running out of codespace! AVRs are awsome little devices. There is just a drive in me to minimize codespace and instruction count as long as it doesn't reduce portability or readablity of code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any chance you could upgrade your compiler to GCC 4.1.x?
I could almoste bet that particular optimization will work
better there.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure how to go about installing (updating) the GCC compiler. :roll: I've been studying here at AVR Freaks, at WinAVR site, gnu site; I'm just spinning my wheels. I guess this is what happens when I use tools that are over my head!

I'm running WinXP.

I've downloaded and unzipped the GCC 4.1.1 from gcc.gnu.org and the install says I need to configure and build before I can use. I think I'm way off course. :oops: I think I might have to just wait patiently for the next WinAVR release.

Thank you though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Waiting for next WinAVR is one option. I think another option
is to replace the WinAVR compiler binary by the AtmanAVR one.
AFAIK, while their product is payware, they are offering the
(GNU) backend tools for free, and you could install them on
top of your WinAVR installation. (Save your old setup before,
of course.)

However, I don't use Windows, so that's hearsay for me. I
always compile my own compiler.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jorg is correct. There was a thread or two about doing this in regard for support for the Mega256 devices. Try searching the forums. I'll post the link if I can find it!

Randy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Randy
I found this thread, it might be the one you mentioned.
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=39014&highlight=mega256

Thank you Jorg, I defiantly owe you a couple of beers.

I will try this as time allows; right now I don't want to change my tools untill I get my current project finished up. I need another computer!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dl8dtl wrote:
However, I don't use Windows, so that's hearsay for me.

'hearsay' or 'heresy' ?

Apologies, couldn't resist...

  • "Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  -- Abraham Lincoln
  • "All right wise guy, where am I?"   -- Daffy Duck
  • "Well, we're safe for now. Thank goodness we're in a bowling alley."  -- Big Bob, Pleasantville
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I needed a dictionary to get that joke...

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.