SRAM Write-Access in C

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

we have been encoding a mixed C and assembly code for the ATMega644 avr-gcc compiler

i need to store data to the address 0x0280 in the SRAM from C so that an assembly function can read it

can you please give me the piece of code to store an integer directly to address 0x0280?

tnx and good day..

-jd

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
uint8_t shared_var __attribute__((section(".mydata")));
LDFLAGS += -section-start=.mydata=0x800280

But why do you need to manually position this (and possibly "bump into" the linker's own allocation). If the .S and .c are linked then let the linker position a shared variable for you:
file.c

uint8_t shared_var;

{
  shared_var= 0x37;
  asm_routine();

file.S

  .extern shared_var
  .global asm_routine
asm_routine:
  LDS R16, shared_var // R16 <-0x37