flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > struc params.

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 18:24
Code:
struc O [X] { match =add, . \{ . eax, X \} }
add O ecx
sub O edx
    
Code:
$ hexdump -C struc_and_macro.bin
$ hexdump -C struc_and_macro.bin
00000000  00 01 02 03 a0 00 00 8a  26 01 00 8a 1e 02 00 8a  |........&.......|
00000010  3e 03 00 66 83 c0 05 66  01 d8 66 83 c0 0a 66 01  |>..f...f..f...f.|
00000020  c8 66 01 c8                                       |.f..|    
Code:
00000021  66 01 c8 ; add eax, ecx
; no sub = mismatch    
Post 30 Apr 2025, 18:24
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 30 Apr 2025, 18:33
Very nice.
Post 30 Apr 2025, 18:33
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 18:48
Names of labels with colons are processed before structures. It won't work like this
Code:
struc P X& { display '. = ', `., 13, 10
  match L=:I,. \{ label L
    display 'L = ', \`L, 13, 10
    display 'I = ', \`I, 13, 10
    irp U, X \\{ I eax, U \\} \} }
name1: add P edx, ecx, 10
name2: sub P eax, ebx, 5    
Code:
$ fasm struc_and_macro.asm
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
. = add
. = sub
1 passes, 36 bytes.
$ hexdump -C struc_and_macro.bin
00000000  00 01 02 03 a0 00 00 8a  26 01 00 8a 1e 02 00 8a  |........&.......|
00000010  3e 03 00 66 83 c0 05 66  01 d8 66 83 c0 0a 66 01  |>..f...f..f...f.|
00000020  c8 66 01 c8                                       |.f..|    
Post 30 Apr 2025, 18:48
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 30 Apr 2025, 19:19
Code:
struc Nn [A] { common local vv
Nn.#. equ vv
vv:
forward . eax, A 
common dec ecx
}

Start: 
      mov ecx,3
      add Nn 10,ecx ;this is line as Nn.add:
      jnz Nn.add

      mov ecx,3
      sub Nn 1,ecx ;this is line as Nn.sub:
      jnz Nn.sub          
Post 30 Apr 2025, 19:19
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 19:56
Code:
$ cat struc_and_macro.asm
use32
struc Nn [A] { common local vv
Nn.#. equ vv
vv:
forward . eax, A
common dec ecx
}

Start:
      mov ecx,3
      add Nn 10,ecx ;this is as Nn.add:
      jnz Nn.add

      mov ecx,3
      sub Nn 1,ecx ;this is as Nn.sub:
      jnz Nn.sub
$ fasm struc_and_macro.asm
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
1 passes, 26 bytes.
$ hexdump -C struc_and_macro.bin
00000000  b9 03 00 00 00 83 c0 0a  01 c8 49 75 f8 b9 03 00  |..........Iu....|
00000010  00 00 83 e8 01 29 c8 49  75 f8                    |.....).Iu.|    
Code:
; mov ecx,3
00000000  b9 03 00 00 00

; add eax, 13 + 12 + 11

; add eax, 10
00000005  83 c0 0a

; add eax, ecx  e.g.  add eax, 3; add eax, 2; add eax, 1
00000008  01 c8

; dec ecx
0000000A  49

; jnz Nn.add
0000000B  75 f8
; 00000000  b9 03 00 00 00 83 c0 0a 01 c8 49 75 f8 
;                          |  |  |  |  |  |  |  ^/ 0xFF
;                          |  |  |  |  |  |  ^---/ 0xFE
;                          |  |  |  |  |  ^------/ 0xFD
;                          |  |  |  |  ^---------/ 0xFC
;                          |  |  |  ^------------/ 0xFB
;                          |  |  ^---------------/ 0xFA
;                          |  ^------------------/ 0xF9
;                          ^---------------------/ 0xF8
; jnz Nn.add -> Nn.add: add eax, 10

; mov ecx, 3
0000000D  b9 03 00 00 00

; sub eax, 2 + 1 + 0

; sub eax, 1
00000012  83 e8 01

; sub eax, ecx  e.g.  sub eax, 3; sub eax, 2; sub eax, 1
00000015  29 c8

; dec ecx
00000017  49

; jnz Nn.sub
00000018  75 f8
; 0000000D  b9 03 00 00 00 83 e8 01 29 c8 49 75 f8
;                          |  |  |  |  |  |  |  ^/ 0xFF
;                          |  |  |  |  |  |  ^---/ 0xFE
;                          |  |  |  |  |  ^------/ 0xFD
;                          |  |  |  |  ^---------/ 0xFC
;                          |  |  |  ^------------/ 0xFB
;                          |  |  ^---------------/ 0xFA
;                          |  ^------------------/ 0xF9
;                          ^---------------------/ 0xF8
; jnz Nn.sub -> Nn.sub: sub eax, 1    
So what's your problem?
Post 30 Apr 2025, 19:56
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1938
Roman 30 Apr 2025, 20:05
No problem.

I used your variant for my task.
Quote:
struc N [A] { forward . eax, A }
Post 30 Apr 2025, 20:05
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 20:45
It's just that these struc don't make sense for the most part.
1) loop instead of dec/jnz
2) one instruction with constants does not need to be calculated in runtime and waste time, but you can stress fasm.
Post 30 Apr 2025, 20:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

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