EASy68K
http://www.easy68k.com/EASy68Kforum/

C array of struct
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1633
Page 1 of 1

Author:  stiglitz [ Mon May 07, 2018 5:45 pm ]
Post subject:  C array of struct

Hi! I am searching how to create an array of simple structures

C code:
Code:
typedef struct t{
   char a;
   int b;
} test;

test x[10];

I don't know where to start, i read the help manual and i think that OFFSET directive can help me but i don't understand how it works

Thank you in advance

Author:  profkelly [ Tue May 08, 2018 11:17 am ]
Post subject:  Re: C array of struct

Here is an example:

Code:
*-----------------------------------------------------------
* Program Number:
* Written by    :
* Date Created  :
* Description   : Creating C style structs.
*
*-----------------------------------------------------------
   ORG   $1000
START:            ; first instruction of program

    offset 0
* Structure 1
test_name   ds.l    1
test_data   ds.l    1
test_foo    ds.l    1
test_bar    ds.l    1
test_struct
    org *

* code may be here
    nop
    nop
    nop

* use the structures with address registers
    lea     struct1,a1
    lea     struct2,a2
   
    move.l  #$1111,(test_name,a1)   ; store some stuff
    move.l  #$2222,(test_data,a1)
    move.l  #$3333,(test_foo,a1)
   
* use the structures directly
    move.l  #$1234,struct2+test_bar

    SIMHALT

* create some structure variables
struct1 ds.b    test_struct
struct2 ds.b    test_struct

   END   START      ; last line of source

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/