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?
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
                        Here's a sample MASM struct from a HID interface routine that I wrote:
SP_DEVICE_INTERFACE_DATA struct
    CbSize      DWORD   ?
    ClassGuid   GUID    <>
    Flags       DWORD   ?
    Reserved    ULONG   ?
SP_DEVICE_INTERFACE_DATA ends
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With