delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/24/21:26:49

From: Dave Bird <dave AT xemu DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: OT: how can I declare and use struct with as.exe ?
Date: Sun, 24 Jan 1999 21:28:45 +0000
Organization: very little
Message-ID: <AeRyyNCNC5q2Ewhk@xemu.demon.co.uk>
References: <789639$att$1 AT nslave1 DOT tin DOT it> <78e00r$msl$1 AT news DOT luth DOT se>
<36AB5D36 DOT 389B AT cam DOT org>
NNTP-Posting-Host: xemu.demon.co.uk
X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209
X-Trace: news.demon.co.uk 917230834 nnrp-09:24231 NO-IDENT xemu.demon.co.uk:158.152.196.209
X-Complaints-To: abuse AT demon DOT net
MIME-Version: 1.0
X-Newsreader: Turnpike (32) Version 4.01 <dQumtnY$x4rJ2u5tL5fS$n2vuP>
Lines: 68
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019