Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Using (16-bit) labels in WinAVR inline asm

Using (16-bit) labels in WinAVR inline asm

2007-07-20 by organix80

Is it possible to use 16-bit constant labels in WinAVR inline assembly?

Normally, in a assembly program, you can do:

lds r16, 0x0412 (just a example)

In mixed C/asm, some variables are stored in SRAM by the compiler. How
to read them using 'lds' and 'sts' in inline assembly?

asm volatile(" ... "
: (inputs)
: (outputs)
);

It seems that there is no 16-bit integer constant in the list. (see
table on ttp://www.scienceprog.com/how-to-use-inline-asm-using-winavr)

The constrains that could be used for addressing, are using the X, Y
or Z pointer, but this requires a lot more instructions then just
'lds' or 'sts'.

Does anyone know the method and constrains that must be used to read C
 SRAM variables using 'lds' and 'sts' in inline assembly?

Regards Laurens

Re: Using (16-bit) labels in WinAVR inline asm

2007-07-20 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "organix80" <organix@...> wrote:
> Does anyone know the method and constrains that must be used
> to read C SRAM variables using 'lds' and 'sts' in inline assembly?

Just use the variable's name, e.g.

char myVar;

int main (void)
{
__asm__ __volatile__
(
 "lds r24, myVar" "\n\t"
 :
 :
);
 return(0);
}

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Re: [AVR-Chat] Using (16-bit) labels in WinAVR inline asm

2007-07-21 by Reza

--- organix80 <organix@hetnet.nl> wrote:

> Is it possible to use 16-bit constant labels in
> WinAVR inline assembly?
> 
> Normally, in a assembly program, you can do:
> 
> lds r16, 0x0412 (just a example)
> 
> In mixed C/asm, some variables are stored in SRAM by
> the compiler. How
> to read them using 'lds' and 'sts' in inline
> assembly?
> 
> asm volatile(" ... "
> : (inputs)
> : (outputs)
> );
> 
> It seems that there is no 16-bit integer constant in
> the list. (see
> table on
>
ttp://www.scienceprog.com/how-to-use-inline-asm-using-winavr)
> 
> The constrains that could be used for addressing,
> are using the X, Y
> or Z pointer, but this requires a lot more
> instructions then just
> 'lds' or 'sts'.
> 
> Does anyone know the method and constrains that must
> be used to read C
>  SRAM variables using 'lds' and 'sts' in inline
> assembly?
> 
> Regards Laurens
> 
> 
> 

this is an example of accessing such things in C using
inline assembly:

/* a simple program to show the usage of assembler
code in your c- programs 8/00 Leitner Harald */

#include<io.h>
uint8_t val1, val2;

int main(void)
{
  outp(0xff,DDRB); /* use all pins on PortB for output
*/
  val1 = 3;
  val2 = 4;
  asm volatile
  (
    "LDS R30,val1\n" /* start of the asm part*/
     LDS R31,val2\n"
     ADD R30,R31\n"
     RJMP do\n" /* definition of jump labels */
     LDI R30,0xFF\n"
     do:STS val1,R30\n"
  ::);
  outp(~val1,PORTB); /* write result of val1+val2 to
Port */
  for (;;){}
}




       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.