avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Global variables in pure assembler??


From: blight
Subject: [avr-gcc-list] Global variables in pure assembler??
Date: Fri, 27 Jun 2003 21:06:40 +0200
User-agent: KMail/1.5.2

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:
        .skip 4,0
bytes_recvd:
        .skip 1,0
---------------------------------------------------------------------
.section .bss
        .lcomm recv_data, 4
        .lcomm bytes_recvd, 1

I also tried with .data segment... The problem is when i look at the 
disassembly of the object file... Here's the source:
; save bytes
carry_set:
        sts             bytes_recvd, __zero_reg__       ; bytes_recvd = 
num_bytes
        clr             __tmp_reg__
        ldi             XH, hi8(recv_data)              ; ...
        ldi             XL, lo8(recv_data)              ; X = recv_data
        add             XL, __zero_reg__                ; ...
        adc             XH, __tmp_reg__                 ; X += num_bytes
save_byte:
        pop             __tmp_reg__                             ; tmp_reg = 
last read byte
        st              -X, __tmp_reg__                 ; *(--X) = tmp_reg
        dec             __zero_reg__
        brne    save_byte

and the disassembly:
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

00000052 <save_byte>:
  52:   0f 90           pop     r0
  54:   0e 92           st      -X, r0
  56:   1a 94           dec     r1
  58:   e1 f7           brne    .-8             ; 0x52


I don't know what exactly happens when objects are linked together... maybe 
it's ok that these values are 0 because they are set by the linker (which 
knows of other objects who also want part of the sram?)

Sorry if this is a stupid question but i'm not much into asm yet

Thanks,
   blight



reply via email to

[Prev in Thread] Current Thread [Next in Thread]