[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Global variables in pure assembler??
From: |
blight |
Subject: |
Re: [avr-gcc-list] Global variables in pure assembler?? |
Date: |
Sat, 28 Jun 2003 00:44:42 +0200 |
User-agent: |
KMail/1.5.2 |
Hi!
I need static vars with global scope! I know that signed/unsigned makes no
difference. I do not need to put any information about the vars into a header
file since they are used in 2 functions - a interrupt handler which pushes
the bytes read onto the stack and when the bitstream has finished saves the
bytes in recv_data.
Then there's
int recv( unsigned char *dst );
This function is meant to copy the 1-4 bytes from recv_data to dst and return
the number of bytes.
Anyway i think it was working since the beginning it's just that i didn't know
enough about the elf format.
Here's the disassembly of main.elf:
000001fc <carry_set>:
1fc: 10 92 64 00 sts 0x0064, r1
200: 00 24 eor r0, r0
202: b0 e0 ldi r27, 0x00 ; 0
204: a0 e6 ldi r26, 0x60 ; 96
206: a1 0d add r26, r1
208: b0 1d adc r27, r0
And that of the object file:
00000044 <carry_set>:
44: 10 92 00 00 sts 0x0000, r1
48: 00 24 eor r0, r0
4a: b0 e0 ldi r27, 0x00 ; 0
4c: a0 e0 ldi r26, 0x00 ; 0
4e: a1 0d add r26, r1
50: b0 1d adc r27, r0
The linker fills in the addresses for SRAM vars because at the time when an
object is compiled it cannot be know what other objects have how many bytes
of SRAM variables :)
Maybe this could be mentioned in some pure ASM FAQ.
blight
On Saturday 28 June 2003 00:16, Larry Barello wrote:
> You want .comm, not .lcomm (which is a local) and you don't need to fool
> around with sections either. They will go into the right section
> automatically.
>
> ...
> .comm myvar, 1 ; Reserve a byte for "myvar"
> .comm yourvar, 4 ; Reserver four bytes for "yourvar"
> .lcomm localvar, 1 ; a single "static" byte (e.g. local)
>
> The type is set in the C header file. You can address it directly with an
> LDS or use lo8() and hi8() to get the address into a register pair.
>
> Cheers!
>
> ----- Original Message -----
> From: "blight" <address@hidden>
> To: <address@hidden>
> Sent: Friday, June 27, 2003 12:06 PM
> Subject: [avr-gcc-list] Global variables in pure assembler??
>
> > Hi!
> >
> > I am writing a driver for some device in pure ASM bcause it needs to be
>
> fast
>
> > and accurate. It needs 2 static vars with global scope (in "C words")
> > I was looking at the output of avr-gcc but i wasn't able to get it
>
> working.
>
> > One var should be unsigned char recv_data[4]; and the other unsigned char
> > bytes_recvd = 0;
> >
> > I tried some different code like the following:
> > ---------------------------------------------------------------------
> > .section .bss
> > recv_data:
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list