hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
719 stars 56 forks source link

`#struct` Directive #135

Open TChapman500 opened 2 years ago

TChapman500 commented 2 years ago

I think I know of a good way to define structures. Have a #struct structName {} directive where each line is a member of the structure. For structure member definitions, #dXX memberName should be the syntax, just like with any other variable outside of a structure. Perhaps there should also be an optional #memberalign bits on the first line of the body to force every new member to be aligned to the specified boundary.

Edit: To access members, one would use structName.memberName, where memberName is the offset from the start of the structure. It would be up to the developer of the program to provide the correct base pointer.

justarandomgeek commented 10 months ago

it's a bit of a hack, but i've found you can do this:

#bankdef struct
{
  #bits 32
  #addr 0x0000
  #size 0x0010
}
#bank struct
#addr 0 
structNameA:
  .memberA: #res 1
  .memberB: #res 1
#bank struct
#addr 0 
structNameB:
  .memberA: #res 2
  .memberB: #res 2

to get labels for structs field offsets. I've put it in a #bank to itself so the pc-fiddling doesn't screw with anything else.

TChapman500 commented 10 months ago

Interesting.