Structures in NASM

Hello fellow programmers,

I've been trying to switch from TASM to NASM.

There's one thing which still doesn't seem to work

properly in NASM.

I can't create structures. I've read the NASM documen-

tation and there was an example about how to use structures. I copied the example and compiled it, but that didn't work either.

Could anyone help me on this?

Thanks in advance,



  • I've had to do this for some windows coding in nasm.

    I'll use the WNDCLASS structure as an example.

    To start off, you need a structure definition, usually in a .inc file:

    struc WNDCLASS

    w_style: resd 1 ;class style

    w_lpfnWndProc: resd 1 ;window procedure

    w_cbClsExtra: resd 1 ;class extra data

    w_cbWndExtra: resd 1 ;window extra data

    w_hInstance: resd 1 ;class owner

    w_hIcon: resd 1 ;icon handle

    w_hCursor: resd 1 ;cursor handle

    w_hbrBackground: resd 1 ;background color

    w_lpszMenuName: resd 1 ;menu name

    w_lpszClassName: resd 1 ;class name


    note the starting and ending "struc/endstruc" tags, the use of unique names

    internal to the structure (w_hIcon rather than hIcon), and the use of

    "reserve" bytes (resb, resw, resd) rather than "define" bytes (db, dw, dd).

    After this, you can declare instances of the structure in the data (or code) segments of your program:


    istruc WNDCLASS

    at w_style, dd 0 ;class style

    at w_lpfnWndProc, dd 0 ;window procedure

    at w_cbClsExtra, dd 0 ;class extra data

    at w_cbWndExtra, dd 0 ;window extra data

    at w_hInstance, dd 0 ;class owner

    at w_hIcon, dd 0 ;icon handle

    at w_hCursor, dd 0 ;cursor handle

    at w_hbrBackground, dd 0 ;background color

    at w_lpszMenuName, dd 0 ;menu name

    at w_lpszClassName, dd 0 ;class name


    note the label ("WndClass:"), such that structre members can be

    referred to as local labels (i.e., "WndClass.w_hIcon"), the use of

    the "istruc/iend" starting and ending tags, the use of the "at"

    keyword when defining bytes, and the "define" rather than "reserve"

    byte commands.


  • Thank you very much.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!