This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Address assignment


----Original Message----
>From: DJ Delorie
>Sent: 14 September 2005 14:17

>>   Ah, you're using a compiler rather than writing assembly?
> 
> You use the compiler to define the structure, and assembly to place
> it.

  I just wanted to suggest an all-in-one-place solution.  There are many
ways to do most things.
  
>>>>         .global _my_struct
>>>> _my_struct = 0xa0001028
>> 
>> you'd want to use a pointer variable:
>> 
>> struct my_struct_type * const my_struct = (struct my_struct_type
>> *)0xa0001028;
> 
> Why add an unneeded level of indirection?  Especially on time-critical
> embedded systems?

  These days, I really have *lots* of faith in the compiler to be able to
optimise that away[*].  But I guess you could always write

#define my_struct (*(struct my_struct_type *)0xa0001028)

and treat it just like an object

   my_struct.x = 3;

    cheers,
      DaveK

[*]   And I tested it as well; with cygwin's x86 gcc-3.4.4, -O0 still loads
the pointer into a register and accesses through it, but at -O1 the pointer
load is eliminated and gcc just emits an absolute memory address in the
instruction.
-- 
Can't think of a witty .sigline today....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]