I decided to use a structure form for data for my xgate program. But I haven't found an easy way to get the size of the structure ("sizeof()"). I guess I could add a byte just before the end of the structure, eg. SIZE DS 1. But that seems wasteful.
C sizeof() can determine memory size of fully defined object. Do you have some typedef for your asm struct? If not and you want just size, then use extra end label and take address difference between two labels, like this
XDEF astruct, astructend
astruct DS.B 1
DS.B 5
astructend
#include <string.h>
extern char astruct, astructend;
memset(&astruct, 0, &astructend - &astruct); // "struct" size to clear is 6
First of all, everything is in assembly language. The following works although it can be prone to mistakes if altered. The structure is defined in an .inc file included by each .asm file. It would be nice if there was a sizeof operator in the assembly language implementation
;MAXIMUM SIZE OF STRUCTURE IS 32 BYTES FOR 5 BIT OFFSET ADDRESSING
MY_STRUCT: STRUCT
VECTOR DS 2
BIT_CNT DS 1
DATA_BYTES DS 4
; ADD VARIABLES AS NEEDED
ENDSTRUCT
;be careful here if structure is modified
SIZEOF_MY_STRUCT EQU MY_STRUCT->DATA_BYTES + 4 - MY_STRUCT->VECTOR
IF SIZEOF_MY_STRUCT > 32
ERR
ENDIF
Mike
Thanks for clarifying it. Yes, no sizeof operator, as well dummy end-of-struct label in struct declaration without DS or something seems being ignored.
But since -> notation works for struct "typedef", you can declare another struct, which would include whole your struct and additional "theend" field
MY_STRUCT_size: STRUCT
msstart TYPE MY_STRUCT
msstop DS.B 1
EDED
ENDSTRUCT
SIZEOF_MY_STRUCT EQU MY_STRUCT_size->msstop - MY_STRUCT_size->msstart