flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > struc params.

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 27 Apr 2025, 06:13
fasmw 1.73
Code:
struc A p1,p2 {
  .#p1 dd ?
  .#p2 dd ?
} 
ptt A x,y 
;in code
mov [ptt.x],5 ;fasm error undefined ptt.x
    
Post 27 Apr 2025, 06:13
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 27 Apr 2025, 06:22
Code:
struc A p1,p2 {
  \.#p1 dd ?
  .#p2 dd ?
} 
ptt A x,y 
;in code
mov [ptt.x],5
mov [ptty],6    
Post 27 Apr 2025, 06:22
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 27 Apr 2025, 06:26
Thanks.
Post 27 Apr 2025, 06:26
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 27 Apr 2025, 06:50
I'll leave my 15th forum post here.
Post 27 Apr 2025, 06:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 27 Apr 2025, 07:16
macomics wrote:
I'll leave my 15th forum post here.
Quote:
Posts: 1111
How you know it is base-2? I always thought it was base-16.
Post 27 Apr 2025, 07:16
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 27 Apr 2025, 09:38
Code:
struc A [p1] { 
      mov eax,p1 ;fasm error
      mov [eax],ebx
      ret
      
  \.#p1 dd ?
}
;in code
ptt A x,y,z

mov ebx,5
call ptt.x 
    
Post 27 Apr 2025, 09:38
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 27 Apr 2025, 10:26
Code:
struc A [p1] { label \.#p1
      mov eax,\.#p1#.var
      mov [eax],ebx
      ret
      
  \.#p1#.var dd ?
}
;in code
ptt A x,y,z

mov ebx,5
call ptt.x     
Post 27 Apr 2025, 10:26
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 27 Apr 2025, 11:21
My variant:
Code:
struc C [p1] { \.#p1: dd 0
      mov eax,\.#p1
      mov [eax],ebx
      ret
} 
;in code 
ptt C x,y

mov ebx,5
call ptt.x+4    

Or this variant:
Code:
struc C [p1] {

      \.#p1: dd 0
 local ..vv
      .#\.#p1#@ equ ..vv
 ..vv:  mov eax,\.#p1
      mov [eax],ebx
      ret
} 
;in code 
ptt C x,y

mov ebx,5
call ptt.x@

mov [ptt.y],8 ;this error undefined ptt.y
    
Post 27 Apr 2025, 11:21
View user's profile Send private message Reply with quote
a



Joined: 10 Apr 2025
Posts: 17
Location: Ukraine
a 27 Apr 2025, 21:32
revolution wrote:
macomics wrote:
I'll leave my 15th forum post here.
Quote:
Posts: 1111
How you know it is base-2? I always thought it was base-16.
Are you a moron?

It's obviously an octal.
Post 27 Apr 2025, 21:32
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 28 Apr 2025, 06:03
Code:
struc A [p1] { forward \.#p1 dd ?
      forward get@#.#\.#p1:
      mov eax,\.#p1
      mov ebx,[eax]
      ret
      forward set@#.#\.#p1:
      mov eax,\.#p1
      mov [eax],ebx
      ret
}

;in code
ptt A x,y,z

mov ebx,5
call set@ptt.x
call get@ptt.y
call set@ptt.z
mov eax,[ptt.x]    
Post 28 Apr 2025, 06:03
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 28 Apr 2025, 06:06
Thanks. Very interesting variant.

I do this variant:
Code:
struc C [p1] {  local ..hh
..hh: dd 0
      .#\.#p1 equ ..hh ;variant work  equ dword [..hh]. in code mov ptt.y,4
 local ..vv
      .#\.#p1#@ equ ..vv

 ..vv:
      mov eax,..hh 
      mov [eax],ebx
      ret
}
;in code 
ptt C x,y

mov ebx,2
call ptt.x@
mov dword [ptt.y],4
    


Last edited by Roman on 28 Apr 2025, 06:27; edited 3 times in total
Post 28 Apr 2025, 06:06
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 28 Apr 2025, 06:09
Have fun
Post 28 Apr 2025, 06:09
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 28 Apr 2025, 06:13
macomics
You macro get error.
Code:
struc A [p1] { forward \.#p1 dd ?
      forward get@#.#\.#p1:
      mov eax,\.#p1
      mov ebx,[eax]
      ret
      forward set@#.#\.#p1:
      mov eax,\.#p1
      mov [eax],ebx
      ret
}

jtt A x,y,z ;error undefined get@jtt.x.x in line mov eax,\.#p1    


I rewrite your macro:
Code:
struc A [p1] {  \.#p1 dd ?
      get@#.#\.#p1:
      mov eax,get@#.#\.#p1-4 ;\.#p1
      mov ebx,[eax]
      ret

      set@#.#\.#p1:
      mov eax,set@#.#\.#p1-4 ;\.#p1
      mov [eax],ebx
      ret
}      


Last edited by Roman on 28 Apr 2025, 09:04; edited 3 times in total
Post 28 Apr 2025, 06:13
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 28 Apr 2025, 07:10
It's easy to fix. Just add a struc name to all the labels.
Code:
struc A [p1] { forward .#\.#p1 dd ?
      forward get@#.#\.#p1:
      mov eax,.#\.#p1
      mov ebx,[eax]
      ret
      forward set@#.#\.#p1:
      mov eax,.#\.#p1
      mov [eax],ebx
      ret
}

jtt A x,y,z    
Post 28 Apr 2025, 07:10
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 28 Apr 2025, 07:15
Thanks. Work fine.
Post 28 Apr 2025, 07:15
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 30 Apr 2025, 05:09
Attached struc to buffer.
Code:
struc G ss,[p1] {  common
      enumm equ 0
      forward
#.#\.#p1 equ ss+enumm 
adr@#.#\.#p1:
      mov eax,ss+enumm
      ret

get@#.#\.#p1:
      mov eax,ss+enumm
      mov ebx,[eax]
      ret

set@#.#\.#p1:
      mov eax,ss+enumm
      mov [eax],ebx
      ret
      enumm equ enumm+4
}

section '.code' code  writeable executable
       
       buf1: .a:  dd 8 dup(0)
             .b:  dd 8 dup(0)

             tu1 G buf1.a,x,y,z
             tu2 G buf1.b,x,y,z
Start:  mov ebx,5
        call set@tu1.x
        call adr@tu2.x
        mov [eax],25
        mov dword [tu2.z],7
    
Post 30 Apr 2025, 05:09
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 30 Apr 2025, 13:50
How I understood macro and struc similar.
My question: what special in struc ? And did have struc something special reserved words ?
Post 30 Apr 2025, 13:50
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 13:56
struc -- allows you to create a macro that will declare instances with a preceding label without a colon, and in this macro there will be an additional reserved word - a dot (the name of this label). Everything else is like in macro.

Code:
use16
macro A {
  .a db 0
  .b db 1
}

struc B {
  .a db 2
  .b db 3
}

instA: A
; instA A - error
instB B
; instB: B - error

mov al, [instA.a]
mov ah, [instA.b]
mov bl, [instB.a]
mov bh, [instB.b]    
Code:
$ cat struc_and_macro.asm
use16
macro A {
  .a db 0
  .b db 1
}

struc B {
  .a db 2
  .b db 3
}

instA: A
instB B

mov al, [instA.a]
mov ah, [instA.b]
mov bl, [instB.a]
mov bh, [instB.b]
$ fasm struc_and_macro.asm
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
1 passes, 19 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                                          |>..|    

Code:
00000000  00 - instA:.a
00000001  01 - instA:.b
00000002  02 - instB.a
00000003  03 - instB.b
00000004  a0 00 00 - mov al, [instA.a]
00000007  8a  26 01 00 - mov ah, [instA.b]
0000000B  8a 1e 02 00 - mov bl, [instB.a]
0000000F  8a 3e 03 00 - mov bl, [instB.a]    
Post 30 Apr 2025, 13:56
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1939
Roman 30 Apr 2025, 18:09
Quote:

instB B

struc can see name instB.
This could using for tricky.

add B ;mean struc B do add
sub B ;mean struc B do sub

Code:
;something like this
if . eq add
     display '+;'
     end if 
if . eq  sub
      display '-;' 
      end if


    


Last edited by Roman on 30 Apr 2025, 18:32; edited 1 time in total
Post 30 Apr 2025, 18:09
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1149
Location: Russia
macomics 30 Apr 2025, 18:20
Code:
struc N [A] { forward . eax, A }
add N 5, ebx, 10, ecx    
Code:
$ 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                                                |.|    

Code:
00000013  66 83 c0 05
; add eax, 5

00000017  66 01 d8
; add eax, ebx

0000001A  66 83 c0 0a
; add eax, 10

0000001E  66 01 c8
; add eax, ecx    
Post 30 Apr 2025, 18:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

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