flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Compact data generation.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
How write macro do this ?
Code:
PackData Tom,proc,q2,buffer,d40,name,b64,flags,b3
PackData Ron,proc,q2,buffer,d40,name,b64,flags,b3
;macro PackData do this
Tom:
.proc:   dq 2  dup (0)
.buffer: dd 40 dup (0)
.name:   db 64 dup (0)
.flags:  db 3  dup (0)

Ron:
.proc:   dq 2  dup (0)
.buffer: dd 40 dup (0)
.name:   db 64 dup (0)
.flags:  db 3  dup (0)
    
Post 29 Jun 2022, 09:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
I try first step. Like this.
Code:
macro PDat chN,chB,chDup {
      chN:
      .#chB: d#chDup dup (0)
      }
macro PDat_ chB,chDup { .#chB: d#chDup dup (0) } 

;in section data write
                PDat          Tom,buffer,d 20
                PDat_         name,b 64
                PDat_         flags,b 3
;in code
mov eax,Tom.flags
mov ebx,Tom.name
    


How union PDat and PDat_ in one macro PackData ?
Or give PDat_ more params than two.
PDat_ name,b 64,flags,b 3


Last edited by Roman on 29 Jun 2022, 11:04; edited 3 times in total
Post 29 Jun 2022, 10:07
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 652
Location: Russia
macomics
Code:
struc PackedData {
  .proc   dq ?, ? ; or 0, 0
  .buffer dd 40 dup ?
  .name   db 64 dup ?
  .flags  db 3 dup ?
}
;in section data write
Tom PackedData
Ron PackedData
;in code
mov rax, [Tom.proc]
lea rdx, [Ron.buffer]
mov rcx, Tom.flags - Ron.flags    
Post 29 Jun 2022, 10:37
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
Nice tricky.
But idea get different size Tom and Ron.
And different numbers .name or .name2 or .name3 or buffer1,buffer2

If i want do this ?
Code:
PackData Tom,proc,q2,buffer,d40,name,b64,flags,b3
PackData Ron,proc,q2,buffer,d120,name,b64,flags,b3,name2,b128
;macro PackData do this
Tom:
.proc:   dq 2  dup (0)
.buffer: dd 40 dup (0)
.name:   db 64 dup (0)
.flags:  db 3  dup (0)

Ron:
.proc:   dq 2  dup (0)
.buffer: dd 120 dup (0)
.name:   db 64 dup (0)
.flags:  db 3  dup (0)
.name2:   db 128 dup (0)
    
Post 29 Jun 2022, 10:50
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 652
Location: Russia
macomics
Code:
struc PackedData proc*, buffer*, name*, flags*, other {
  .proc   d#proc   dup 0
  .buffer d#buffer dup 0
  .name   d#name   dup 0
  .flags  d#flags  dup 0
  match any, other \{ .other d#other dup 0 \}
}
;in section data write
Tom PackedData q 2, d 40, b 64, b 3
Ron PackedData q 2, d 120, b 64, b 3, b 128
;in code
mov rax, [Tom.proc]
lea rdx, [Ron.buffer]
mov ecx, Tom.proc - Ron.other    
or
Code:
struc PackedData proc*, buffer*, name*, flags*, other {
  .proc   proc 0
  .buffer buffer 0
  .name   name 0
  .flags  flags 0
  match any, other \{ .other other 0 \}
}
;in section data write
Tom PackedData dq 2 dup, dd 40 dup, db 64 dup, db 3 dup
Ron PackedData dq 2 dup, dd 120 dup, db 64 dup, db 3 dup, du 128 dup
;in code
mov rax, [Tom.proc]
lea rdx, [Ron.buffer]
mov ecx, Tom.proc - Ron.other    
Post 29 Jun 2022, 11:11
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
ok. If i want write this.
I must write new struc PackedData2 proc*, buffer*, name*, flags*, other,other2 ?
Code:
PackData Ron,proc,q2,buffer,d120,name,b64,flags,b3,name2,b128,buffer2,d36
;macro PackData do this

Ron:
.proc:   dq 2  dup (0)
.buffer: dd 120 dup (0)
.name:   db 64 dup (0)
.flags:  db 3  dup (0)
.name2:   db 128 dup (0)
.buffer2: dd 36
    

and i want get not Ron.other, i want get Ron.name2 !
Or Ron.buffer2
Post 29 Jun 2022, 11:19
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 652
Location: Russia
macomics
Code:
struc PackedData [args] { forward match name==value, args \{ \.\#name value 0 \} }
 
Tom PackedData proc=dq 2 dup, buffer=dd 40 dup, name=db 64 dup, flags=db 3 dup
Ron PackedData proc=dq 2 dup, buffer=dd 120 dup, name=db 64 dup, flags=db 1 dup, name2=db 100 dup

mov     eax, Tom.name
mov     edx, Ron.name2
mov     ecx, Ron.name2 - Tom.proc + 100    
Post 29 Jun 2022, 12:00
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
Thanks.
Thats i wanted.
Post 29 Jun 2022, 12:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
My variant:
Code:
struc ??? [args] { forward match name==value, args \{ \.\#name d\#value dup (0) \} }
Ron ???       proc=q 2, buffer=d 40, name=b 64, flags=b 3
    
Post 29 Jun 2022, 12:22
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
My question is how get name struc ?
I mean Ron ???
How in struc ??? Get name Ron ?
Some how struc know input name ?
I want auto apply in end stru Ron.End
Post 29 Jun 2022, 12:51
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
Code:
macro ??? chName,[args] { common
          chName:
          forward match name==value, args \{ \.\#name d\#value dup (0) \}
          common
          chName#.End:
          chName#.size = chName#.End-chName
         }   
;in data
???          Ron,proc=q 2, buffer=d 5,name=b 64, flags=b 3
    
Post 29 Jun 2022, 13:08
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 652
Location: Russia
macomics
Code:
struc ??? [args] { forward match name==value, args \{ \.\#name d\#value dup (0) \}
  label .End }
Ron ???       proc=q 2, buffer=d 40, name=b 64, flags=b 3    
Post 29 Jun 2022, 15:15
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1251
Roman
Thanks.
Right is this:
Code:
struc ??? [args] { forward match name==value, args \{ \.\#name d\#value dup (0) \}
  common label .End }
    
Post 29 Jun 2022, 16:11
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.