Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struct or class in assembly

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?

like image 973
Vahid Kharazi Avatar asked Oct 17 '25 09:10

Vahid Kharazi


2 Answers

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
like image 176
Aki Suihkonen Avatar answered Oct 19 '25 12:10

Aki Suihkonen


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
like image 39
Brian Knoblauch Avatar answered Oct 19 '25 11:10

Brian Knoblauch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!