flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro sizeof. for all fasm data

Author
Thread Post new topic Reply to topic
Dima1205



Joined: 02 Jul 2023
Posts: 24
Location: Russian, Moscow
Dima1205 02 Jul 2023, 18:14
Dear collegues, I propose a solution to problems with the use of sizeof. before all data. To do this, you need to supplement the definitions of FASM directives using struc in this way:
Code:
;Директивы sizof - по умолчанию её нет - поэтому придется доопределять 
;данные.

;Директивы sizeof по выбранным данным (нужно для програботки данных): 
sizeof.db fix 1
sizeof.dw fix 2
sizeof.du fix 2
sizeof.dd fix 4 
sizeof.dp fix 6 
sizeof.df fix 6 
sizeof.dq fix 8 
sizeof.dt fix 10 
;Исходные константы для резервирования данных: 
sizeof.rb fix 1
sizeof.rw fix 2
sizeof.rd fix 4 
sizeof.rp fix 6 
sizeof.rf fix 6 
sizeof.rq fix 8 
sizeof.rt fix 10

;
;
; Улучшенный механизм данных - дополняем размерностью автоматически:
;
;
struc db [val]
{
  common  
  match any, val \{ . db val \}
  match , val \{ . db ? \}
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.db
}
;
struc du [val]
{
  common  
  match any, val \{ . du val \}
  match , val \{ . du ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.du
}

struc dw [val]
{
  common  
  match any, val \{ . dw val \}
  match , val \{ . dw ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.dw
}

struc dd [val]
{
  common  
  match any, val \{ . dd val \}
  match , val \{ . dd ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.dd
}

struc dq [val]
{
  common  
  match any, val \{ . dq val \}
  match , val \{ . dq ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.dq
}

struc df [val]
{
  common  
  match any, val \{ . df val \}
  match , val \{ . df ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.df
}

struc dt [val]
{
  common  
  match any, val \{ . dt val \}
  match , val \{ . dt ? \} 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = sizeof.dt
}
;
;
; Улучшенный механизм резервирования данных:
;
;
struc rb val
{
  . rb val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}

struc rw val
{
  . rw val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}

struc rp val
{
  . rp val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}

struc rd val
{
  . rd val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}

struc rt val
{
  . rt val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}

struc rq val
{
  . rq val 
  restore .size 
  .size = $ - . 
  restore sizeof.#.
  sizeof.#. = $ - .
}    


Description: Demo Win32 program to used this macros (sizeof.)
Download
Filename: demo.zip
Filesize: 1.62 KB
Downloaded: 184 Time(s)


_________________
Best regards, Dmitry
Post 02 Jul 2023, 18:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 02 Jul 2023, 18:44
The restore does nothing because there is no matching equ or define.

When you assign a value with = it is the assembler that does this. When using restore it is the preprocessor. So the two are not compatible with each other.
Post 02 Jul 2023, 18:44
View user's profile Send private message Visit poster's website Reply with quote
Dima1205



Joined: 02 Jul 2023
Posts: 24
Location: Russian, Moscow
Dima1205 02 Jul 2023, 20:31
Restore is needed as a protection if the constant has been defined before. For example from this phenomenon.
Code:
define sizeof.test3 1
test3 db "test",0
    

Therefore, I left it - in general, it is not required, I agree here.

_________________
Best regards, Dmitry
Post 02 Jul 2023, 20:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 02 Jul 2023, 20:40
You can also use irpv to extend the defensiveness against multiple preceding equ or define.
Code:
define sizeof.test3 1
define sizeof.test3 1
;...
irpv x,sizeof.test3 {restore sizeof.test3} ; remove any/all preceding equates/defines
sizeof.test3 = 3    
Post 02 Jul 2023, 20:40
View user's profile Send private message Visit poster's website Reply with quote
Dima1205



Joined: 02 Jul 2023
Posts: 24
Location: Russian, Moscow
Dima1205 02 Jul 2023, 21:03
Thank you. I think these macros will be a good help in the standard package.
They add 2 constants:
1.sizeof. - the size of the data type, or the size of the reserved data.
2. size. - is simply the size of the data that the given directive contains.
Post 02 Jul 2023, 21:03
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.