flat assembler
Message board for the users of flat assembler.

Index > Main > How to embed 32 times one structure into another structure?

Author
Thread Post new topic Reply to topic
NETSTALKER



Joined: 17 Apr 2020
Posts: 10
Location: fidonet
NETSTALKER 27 May 2023, 11:33
How to embed 32 times one structure into another structure?

structure in C:
typedef struct VkPhysicalDeviceMemoryProperties {
uint32_t memoryTypeCount;
VkMemoryType memoryTypes[VK_MAX_MEMORY_TYPES];
uint32_t memoryHeapCount;
VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS];
} VkPhysicalDeviceMemoryProperties;

structure in MASM:
VkPhysicalDeviceMemoryProperties STRUCT
memoryTypeCount DWORD ? ; uint32_t
memoryTypes VkMemoryType VK_MAX_MEMORY_TYPES DUP (<>)
memoryHeapCount DWORD ? ; uint32_t
memoryHeaps VkMemoryHeap VK_MAX_MEMORY_HEAPS DUP (<>)
VkPhysicalDeviceMemoryProperties ENDS

VK_MAX_MEMORY_TYPES equ 32
VK_MAX_MEMORY_HEAPS equ 16

How it's work in FASM?
memoryHeaps VkMemoryHeap VK_MAX_MEMORY_HEAPS DUP (<>) - not work
memoryTypes dd 32 dup (VkMemoryType) - not work
memoryTypes dd 32 dup <VkMemoryType> - not work
memoryTypes VkMemoryType 32 dup(?) - not work
memoryTypes rep 32 VkMemoryType -not work
memoryTypes rept 32 VkMemoryType -not work
or another ...
Post 27 May 2023, 11:33
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 27 May 2023, 12:09
Code:
macro array size,type,[value] {
 common local index
        index = 0
 forward
                index = index + 1
 common
        match ,value \{ index = 0 \}
        if index>size
                \can\`\t \fit \in type[size]
        end if
        if size
 forward
                type value
 common
        end if
        repeat size-index
                type
        end repeat
        }

macro arrayoverload [type] {
        macro type definition& \{
                match [size] values, definition: \\{
                        match vals:,values \\\{ array size,type,vals \\\}
                        match :,values \\\{ array size,type \\\}
                        overloaded equ \\}
                match =overloaded,overloaded \\{ type definition \\}
                restore overloaded\}
        struc type definition& \{
                virtual
                        . type
                end virtual
                type definition \} }    
Code:
arrayoverload VkMemoryType,VkMemoryHeap 

struct VkPhysicalDeviceMemoryProperties 
memoryTypeCount dd ?
memoryTypes VkMemoryType[VK_MAX_MEMORY_TYPES]; also thou could init any defaults within <> for any array item 
memoryHeapCount dd ?
memoryHeaps VkMemoryHeap[VK_MAX_MEMORY_TYPES]
ends    
Post 27 May 2023, 12:09
View user's profile Send private message Send e-mail Reply with quote
NETSTALKER



Joined: 17 Apr 2020
Posts: 10
Location: fidonet
NETSTALKER 27 May 2023, 13:42
ProMiNick wrote:
Code:
macro array size,type,[value] {
 common local index
        index = 0
 forward
                index = index + 1
 common
        match ,value \{ index = 0 \}
        if index>size
                \can\`\t \fit \in type[size]
        end if
        if size
 forward
                type value
 common
        end if
        repeat size-index
                type
        end repeat
        }

macro arrayoverload [type] {
        macro type definition& \{
                match [size] values, definition: \\{
                        match vals:,values \\\{ array size,type,vals \\\}
                        match :,values \\\{ array size,type \\\}
                        overloaded equ \\}
                match =overloaded,overloaded \\{ type definition \\}
                restore overloaded\}
        struc type definition& \{
                virtual
                        . type
                end virtual
                type definition \} }    
Code:
arrayoverload VkMemoryType,VkMemoryHeap 

struct VkPhysicalDeviceMemoryProperties 
memoryTypeCount dd ?
memoryTypes VkMemoryType[VK_MAX_MEMORY_TYPES]; also thou could init any defaults within <> for any array item 
memoryHeapCount dd ?
memoryHeaps VkMemoryHeap[VK_MAX_MEMORY_TYPES]
ends    


Thank you very much. It looks beautiful. But is there a way to solve the issue with built-in methods? Maybe not so beautiful, but so that you don't need to introduce new entities - macros.

_________________
SEARCH INTERESTING FILES
Post 27 May 2023, 13:42
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 27 May 2023, 15:28
not so beautifyl - peace of cake (that is legacy fasm solution for arrays):
Code:
struct VkPhysicalDeviceMemoryProperties 
memoryTypeCount dd ?
memoryTypes db sizeof.VkMemoryType*VK_MAX_MEMORY_TYPES dup (?) 
memoryHeapCount dd ?
memoryHeaps db sizeof.VkMemoryHeap*VK_MAX_MEMORY_TYPES dup (?)
ends    
Post 27 May 2023, 15:28
View user's profile Send private message Send e-mail Reply with quote
NETSTALKER



Joined: 17 Apr 2020
Posts: 10
Location: fidonet
NETSTALKER 27 May 2023, 16:18
ProMiNick wrote:
not so beautifyl - peace of cake (that is legacy fasm solution for arrays):
Code:
struct VkPhysicalDeviceMemoryProperties 
memoryTypeCount dd ?
memoryTypes db sizeof.VkMemoryType*VK_MAX_MEMORY_TYPES dup (?) 
memoryHeapCount dd ?
memoryHeaps db sizeof.VkMemoryHeap*VK_MAX_MEMORY_TYPES dup (?)
ends    


Thank you. I did the same myself. It's worse, but it works. Thank you very much. Your previous example may contain an error. My program crashed without an message about error.

_________________
SEARCH INTERESTING FILES
Post 27 May 2023, 16:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.