Source does not match disassembly

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

Hi

I am using Atmel studio6 - a fairly recent version.
Optimization is set to none and debugging is set to maximum but for some reason it looks as if some form of optimization is happening. I am not an assembler user so my observation might be wrong but the source does not seem to match the disassembly. For example:

uint8_t CheckQuad(uint8_t * Direction)
{

	MoveCount = GetQuadCount();
	if(MoveCount != OldMove)//has it moved?
	{
		*Direction = GetQuadDirection();//get direction of encoder knob - CCW_DIR or CW_DIR
		OldMove = MoveCount;
		return MoveCount + 1;//add one because movecount is 0 - 23 (= 24 counts)
	}
	return 0;
}

becomes this in the LSS file:

uint8_t CheckQuad(uint8_t * Direction)
{
     a46:	80 91 8e 21 	lds	r24, 0x218E
     a4a:	98 17       	cp	r25, r24
     a4c:	71 f0       	breq	.+28     	; 0xa6a 
     a4e:	d0 df       	rcall	.-96     	; 0x9f0 
     a50:	28 2f       	mov	r18, r24

	MoveCount = GetQuadCount();
     a52:	89 81       	ldd	r24, Y+1	; 0x01
     a54:	9a 81       	ldd	r25, Y+2	; 0x02
     a56:	fc 01       	movw	r30, r24
     a58:	20 83       	st	Z, r18
	if(MoveCount != OldMove)//has it moved?
     a5a:	80 91 9c 21 	lds	r24, 0x219C
     a5e:	80 93 8e 21 	sts	0x218E, r24
     a62:	80 91 9c 21 	lds	r24, 0x219C
	{
		*Direction = GetQuadDirection();//get direction of encoder knob - CCW_DIR or CW_DIR
     a66:	8f 5f       	subi	r24, 0xFF	; 255
     a68:	01 c0       	rjmp	.+2      	; 0xa6c 
     a6a:	80 e0       	ldi	r24, 0x00	; 0
     a6c:	0f 90       	pop	r0
     a6e:	0f 90       	pop	r0
     a70:	df 91       	pop	r29
     a72:	cf 91       	pop	r28
		OldMove = MoveCount;
     a74:	08 95       	ret

In full debug mode I would have expeceted the source and asembly to be more aligned with each other.

All comments welcome.

Thanks

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

Even with optimisation turned off it has been reported that some low levels of optimisation occur.

what is the part that you thinks looks particularly obscure?

regards
Greg

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

It is not so much about looking obscure but more about setting break point when debugging.
In the example above I set a breakpoint at OldMove = MoveCount; But because the source does not match the actual code the break point is in the wrong place. You also have the effect when single stepping that it jumps all over the place.

I think that I have just figured out the cause. Even though I had full debug set and no optimization I did have "Relax Branches (-mrelax)" turned on. This seems to be the problem :cry: Would it not make more sense if the IDE turned this off when in debug with no optimization?

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

Quote:

This seems to be the problem

There was a problem in older AS6 with -relax causing the source annotation to get out of step. I reported this to Atmel (see thread here) and they fixed it in a later release. I therefore strongly suspect you aren't using 6.1.2674

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

Quote:
I therefore strongly suspect you aren't using 6.1.2674

You strongly suspect right :) I did not notice that there was an update .. thanks