Mail Archives: djgpp/1999/01/24/21:26:49
In article <36AB5D36 DOT 389B AT cam DOT org>, Vic <tudor AT cam DOT org> writes
>doesn`t help much. the following C code
>
>struct t
>{
>int a;
>long b;
>long long c;
>};
>
>struct t out_main;
>
>main()
>{
>out_main.a=5;
>out_main.b=654;
>out_main.c=13466;
>
>}
see below............................
>gives this:
> movl $654,_out_main+4
> movl $13466,_out_main+8
> movl $0,_out_main+12
>
>
>The way it declares a struct, only when it is global (if it`s in a
>fuction it uses the stack) is by using
> .comm name,length:
>.comm _out_main,16 declares an out_main struct 16 bytes long.
>you access the members by their offset in the struct.
OK. You can prettify the code in two ways.
First, you can write equates for the field offsets. For example
with struct x1{ long donkey; long giraffe; long elephant; };
it might be....
donkey equ 0;
giraffe equ 4;
elephant equ 8;
mov eax,out_main+giraffe;
Some assemblers allow a dot instead of a plus.
Some allow......
x1 struct
donkey dd 0
giraffe dd 0
elephant dd 0
x1 ends; to equate the offsets for you automatically.
If this one doesn't then get a better assembler.
(OTOH maybe it does, but the compiler can't be bothered to put
all the fancy symbolic names into its assembler output which
a human programmer would add for maximum clarity).
--
^-^-^-@@-^-;-^ http://www.xemu.demon.co.uk/
(..)__u news:alt.smoking.mooses
- Raw text -