Variable head scratching??!!

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

Hi, I have a piece of code that looks like this:

static uint8_t watchdogs;

void
clrWatchdog(uint8_t watchdog)
{
   watchdogs &= ~(watchdog);
}

which then results in:

com r24
lds r25,0x0000
and r25,r24
sts r25,0x03E4
ret

This doesn't make sense to me, as it clearly knows the address of variable watchdog because it stores it back to 0x03E4 but chooses to get it from address 0x0000.

I'm relatively new to coding in C though and it might make sense to someone more experienced, please help if you can... I really would like it to work properly.

Thanks

John.

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

In addition, i have just expanded the statement to

   watchdogs = watchdogs & ~(watchdog);

and all is well.

Still would like an explaination if anyone has one.

Cheers

John.

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

Hmm, actually this is what is happening:

Routine clrWatchdog is being changed, when the debugger steps to it for the 1st few times it appears ok, lds r25,0x03E4 then it gets changed to lds r25,0x0000.

Now I'm confused!

Can anybody help?!

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

It looks to me like you are looking at unlinked code (where the addresses have not yet been "fixed up" so contain 0x0000). How are you examining this code exactly?

Cliff

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

Quote:
for the 1st few times it appears ok, lds r25,0x03E4 then it gets changed to lds r25,0x0000

0x03E4 is a constant in flash, so it can't possibly be changed. Are you debugging in the simulator or with JTAG?

Regards,
Steve A.

The Board helps those that help themselves.

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

I am using the JTAG ICE II programmer, the constant is held in program memory you are correct. I have come to the conclusion it is a problem with the debugger. when i look at the code in the disassemler window it doesn't match the memory window, i.e the window says 9091e403 and the dissasembler window tells me the code is 91900000. Clearly it is out to frustrate me today as this is not the only wierd unexplainable behaviour!
When i look at r25 with the register watch it is behaving as it should!

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

That does like a bug. You can send a problem report to avr@atmel.com and perhaps reference this thread.