Losing data in ASM

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Decided to just go back to solid code and start over, issue didn't come back, disregard all of this.

 

 

 

 

I know ASM needs to be thought out well and if your not careful changing existing C code can cause undesired results in ASM, and that is more then likely what I just ran in to.

 

My variable count and  my array all of a sudden are showing up empty. I was able to fix my count by going from

this  register  unsigned char count ;

to this  register  unsigned char count ASM("r19");

but nBuffer is also empty now. So I put count back to figure out the real issue.

 

 

EDIT - I was able to fix the buffer by  making a temp array

unsigned char data[35];

memcpy(nBuffer,data,35);

but I just feel this is a ugly bandiad.

 

 

buffer is global
volatile unsigned char nBuffer[35];
count is local (assuming register is not global)

register  unsigned char count ;

 

ASM is inline and still working as should according to debug. I was working on the C code and then noticed my ASM was no longer saving variables. I tried a few reverts with no luck.

asm volatile(
		"	clr %0					\n" //clear counter
		"	clr r17					\n" //clear temp
		"	ldi r18,8				\n" //set counter
		"	ld  r17, Z 				\n" //load Z to r17
		"	rjmp nextBit	\n"
"nextByte:\n"
		"	ldi r18,8				\n" //set counter back to 8
		"	st  Z+, r17 			\n" //load r17 to z and go to next element in array
		"	ld  r17, Z 				\n" //load Z to r17
"nextBit:\n"
		" 	ldi r16, 0xff			\n" //set exprire counter
"waitlow:\n"//start bit.
		"	dec r16					\n" //time out counter
		"	breq exit				\n" //exit when we are zero( Z  flag and dec are equal. )
//find the next falling edge to sync
		"	sbic %2, 5				\n" //check if low,then skip
		"	rjmp waitlow			\n" //wait while low.
		"	nop						\n" //move 1us in to place.
		.
.
.
.
.
.
.
.
.
		: 	"=&r" (count)						// %0
		: 	"z" ((unsigned char volatile *)nBuffer),// %1
			"I" (_SFR_IO_ADDR(GCN64_DATA_PIN)),	// %2
			"I" (_SFR_IO_ADDR(PORTB))			// %3
		: 	"r16","r17","r18"
	);

after the following code, count and all my data in nBuffer is set to 0.

 

Fixing count was fixed by specifying a register but I'm trying to figure out what did this. From the lst file I see it puts my array in to r30/31 pairs. The ASM reference it by z and puts it in to r17. Do I need to so something with r30/31?  

Last Edited: Tue. Feb 23, 2021 - 11:05 PM