This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: structures in assembly code


mccoards@netscape.net writes:

Questions about the assembler should not be sent to gcc-help.  They
should be sent to bug-binutils@gnu.org or binutils@sources.redhat.com.
See http://sourceware.org/binutils/.  Or just type as --help.

> Im trying to port code from on old BSO 68K assembler to the gcc
> assembler.  I have run into a problem converting the structures.  In
> BSO you can make as many structures as you want by starting with a
> BSO directive of OFFSET len, and by ending it with SECTION.
> 
> Example:
>     OFFSET 0
> item_start   equ *
> item1        DS.B 20
> item2        DS.W 1
> item3        DS.L 2
> item_end equ *
> item_length equ item_end-item_start
>     SECTION
> 
> item1 would equate to 0, and item2 would equate to 20 and item3
> would equate to 22.  So in a real section you could define a data
> structure and then easily referance the items in the structure
> Example:
>         SECTION .bss
> item DS.B item_length
> 
>         SECTION .text
>    LEA item,A0
>    MOVE.W #5,item2(A0)
> 
> I have looked at the gas manual and have found .offset and .struct,
> but I still cant figure out how (if its even possible) to create
> this type of structure without the assembler or linker
> complainning. Any help would be greatly appreciated.

There is an example of the use of .struct in the gas manual.

Here is how to do your example with gas (I used x86 instructions since
I don't happen to have an m68k assembler built):

.struct 0
item_start:
item1:
        .struct item1 + 20
item2:
        .struct item2 + 2
item3:
        .struct item3 + 8
item_end:
item_length = item_end - item_start

        .bss
item:
        .space item_length

        .text

        mov     #item,%eax
        movw    #5,item2(%eax)

Ian


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