struct or class in assembly

流过昼夜 提交于 2019-12-01 00:10:05

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!