struct or class in assembly

assembly, class, macros, masm

Solution

Tasm supports eg.

struc String  // note: without 't' at the end
   size   dw 100
   len    dw 10
   data   db 0 dup(100)
ends String

Gnu assembler also has a `.struct` directive.

The syntax for MASM is:

String STRUCT
    size dw 100
    len dw 10
String ENDS

Usage again from the same MASM manual:

ASSUME eax:PTR String
mov ecx, [eax].size,
mov edx, [eax].len
ASSUME eax:nothing
.. or ..
 mov ecx, (String PTR [eax]).size   // One can 'cast' to struct pointer

One can also access a local variable directly

mov eax, myStruct.len

Problem

I need something like struct or class in c++ For example I need a class with an array and two attribute (size and len) and some function like append and remove . How can I implement this in assembly with macros and procedures?

Original source