flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > CALM implementation of STRUCT - new tricks

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8344
Location: Kraków, Poland
Tomasz Grysztar 02 Feb 2024, 17:34
ProMiNick wrote:
struct redefinition - could it be solved. struct define labels, not symbolic vars. redefinition of labels cause error.
Without altering the STRUCT implementation, you could use fasmg's namespaces:
Code:
struct POINT
        x dd ?
        y dd ?
ends

namespace ?16bit

        define sizeof? sizeof   ; give a local anchor for the definitions like sizeof.POINT

        struct POINT
                x dw ?
                y dw ?
        ends

        my POINT 1,2    ; 4 bytes

end namespace

other POINT 3,4         ; 8 bytes    
Post 02 Feb 2024, 17:34
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 786
Location: Russian Federation, Sochi
ProMiNick 02 Feb 2024, 22:03
It looks very beautyful and intuitive and very readable. thanks.
Post 02 Feb 2024, 22:03
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 03 Feb 2024, 07:38
struct POINT
x dd ?
y dd ?
ends

struct POINTshort
x dw ?
y dw ?
ends

Very clear and easy rewrite another programing languages.
And not do this magic spells .
Code:
 
 namespace ?16bit ;if only this one command auto convert struct to 16 bits woold be nice

        define sizeof? sizeof   

end namespace    
Post 03 Feb 2024, 07:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8344
Location: Kraków, Poland
Tomasz Grysztar 03 Feb 2024, 09:24
Roman wrote:
Code:
 
 namespace ?16bit ;if only this one command auto convert struct to 16 bits woold be nice

        define sizeof? sizeof    
That "define" line might be obscure, but it is only needed with implementation that maintains the legacy definitions like "sizeof.POINT" compatible with syntax of fasm 1. And they are only there for compatibility, because modern fasmg's syntax is "sizeof POINT" where "sizeof" is an actual operator and the length of structure is given in metadata of the "POINT" symbol.

With "struct" macro cleaned up to not define such constants, switching the namespaces would be enough.
Post 03 Feb 2024, 09:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20132
Location: In your JS exploiting you and your system
revolution 03 Feb 2024, 11:04
Roman wrote:
POINTshort
A lot of MS documentation likes to use a prefix character to indicate the size. So ...

lPOINT - long point (dwords)
sPOINT - short point (words)

Anyone familiar with OOP would baulk at "ugly" naming requirements like that, and everything would simply be POINT where the size is inferred from the context. But assembly and OOP are at odds with each other in many ways. For example how could one correctly write this?
Code:
mov reg,[MY_POINT.x] ; what register size goes here? ax? eax?    
We need a way to discover the size.
Code:
if sizeof.MY_POINT.x = 16
  movzx eax,[MY_POINT.x]
else
  mov eax,[MY_POINT.x]
end if    
But then is it correct to use movzx? Maybe the points can go negative, so movsx might be correct.

What would be a way to embed sign information? Asm syntax doesn't have any unsigned type operator like C does. Could this exist?
Code:
if sizeof.MY_POINT.x = 16
  if signof.MY_POINT.x = -1 ; signed?
    movsx eax,[MY_POINT.x]
  else
    movzx eax,[MY_POINT.x]
  end if
else
  mov eax,[MY_POINT.x]
end if    
Post 03 Feb 2024, 11:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8344
Location: Kraków, Poland
Tomasz Grysztar 03 Feb 2024, 11:21
Tomasz Grysztar wrote:
With "struct" macro cleaned up to not define such constants, switching the namespaces would be enough.
Update: I changed the implementation of "struct" in the fasm2 package so that the global symbols like "sizeof.POINT" are defined as simple symbolic links to names that are evaluated in local context. This cleans up all the redefinition issues and even makes the global symbols be evaluated with local values:
Code:
struct POINT
        x dd ?
        y dd ?
ends

namespace ?16bit

        struct POINT
                x dw ?
                y dw ?
        ends

        db sizeof.POINT ; 4

end namespace

db sizeof.POINT ; 8    
Post 03 Feb 2024, 11:21
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 786
Location: Russian Federation, Sochi
ProMiNick 03 Feb 2024, 11:28
signof could be of 3 values: undefined - no sign limit (-128..255), 0 - strict unsign (0..255), 1 strict sign (-128..127), or 0,1,-1 to be numeric, not symbolic
Post 03 Feb 2024, 11:28
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1701
Roman 03 Feb 2024, 13:43
revolution
When all else fails, read the source


Quote:

lPOINT - long point (dwords)
sPOINT - short point (words)

mov reg,[MY_POINT.x] ; what register size goes here? ax? eax?


Nice remark.
MY_POINT must inherit the type of struct.
Code:
If MY_POINT lPOINT
mov reg,type [MY_POINT.x] ;mov eax,dword [MY_POINT.x]

If MY_POINT sPOINT
mov reg,type [MY_POINT.x] ;movzx eax,word [MY_POINT.x]

type gives cool tricks.
If MY_POINT sPOINT
getAllType reg, [MY_POINT] ;generated this code

movzx eax,word [MY_POINT.x]
movzx ebx,word [MY_POINT.y]    
Post 03 Feb 2024, 13:43
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3946
Location: vpcmipstrm
bitRAKE 03 May 2024, 14:34
For windows, many of the structures are an incorrect size. This happens when alignment of an element promotes structure alignment, and trailing elements are of a lesser alignment. By updating macro struct?.check name, the problems can be detected:
Code:
if sizeof name mod maxalignment > 0
        repeat 1, N:sizeof name
        display 'warning: struct ',`name,'(',`N,') not aligned to its natural boundary',10
        end repeat
end if    
... this addition also checks the structure as a whole meets the max alignment requirement.

This impacts a number of fasm2 structures in 64-bit:
Code:
warning: struct WIN32_FIND_DATA(318) not aligned to its natural boundary
warning: struct WIN32_FIND_DATAA(318) not aligned to its natural boundary
warning: struct CLIENTCREATESTRUCT(12) not aligned to its natural boundary
warning: struct TEXTMETRIC(53) not aligned to its natural boundary
warning: struct HD_ITEM(36) not aligned to its natural boundary
warning: struct REBARBANDINFO(68) not aligned to its natural boundary
warning: struct TOOLTIPTEXT(124) not aligned to its natural boundary
warning: struct TC_ITEM(36) not aligned to its natural boundary
warning: struct NM_DATETIMECHANGE(44) not aligned to its natural boundary
warning: struct NM_DATETIMESTRING(52) not aligned to its natural boundary
warning: struct CHOOSEFONT(100) not aligned to its natural boundary    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 03 May 2024, 14:34
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< 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.