flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro not see value.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 19 Dec 2022, 12:50
Fasmw 1.73
Code:
macro StateHero val {
inc [.v1] ;using as virtual ? for offset [ebx+.v1]
sub [.v2],10
}
;I have 3 equal procs like proc A
proc A
mov edx,.Hero
call B
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp

proc B
 StateHero edx ;error fasm. Undefined .v1 and .v2
 ret
endp
    

My code more big and complicated. And i want easy fix this problem.
And dont write new struct for Hero.
Post 19 Dec 2022, 12:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 19 Dec 2022, 18:07
My variant.
Code:
macro StateHero val {
inc [ecx+.v1-.v1] 
sub [ecx+.v2-.v1],10
}
;I have 3 equal procs like proc A
proc A
mov edx,.Hero
mov ecx,.v1
call B
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp

proc B
 StateHero edx 
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp    
Post 19 Dec 2022, 18:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20357
Location: In your JS exploiting you and your system
revolution 19 Dec 2022, 20:17
The macro has nothing to do with the problem.
Code:
A:
  .v1 db ?  ; local name has limited scope
B:
  mov al,[A.v1] ; Okay
  mov al,[.v1]  ; undefined B.v1    
You need to fully qualify the name A.v1 or use a global name.
Code:
A:
  ..v1 db ? ; global name is seen everywhere.
B:
  mov al,[..v1] ; Okay    
Post 19 Dec 2022, 20:17
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 19 Dec 2022, 21:36
Quote:

A:
..v1 db ? ; global name is seen everywhere.
B:

I have three procs with .v1
Post 19 Dec 2022, 21:36
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 19 Dec 2022, 21:50
Do not forget to call your procedures from anywhere. Othervice the procedure's body will be blank for rest of your program.
Use global label trick for short names.
Post 19 Dec 2022, 21:50
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: 20357
Location: In your JS exploiting you and your system
revolution 19 Dec 2022, 22:04
To fully qualify the name you need to give the prefix.
Code:
macro StateHero prefix,val {
  inc [prefix#.v1]
  sub [prefix#.v2],val
}
proc A
  .v1:
  .v2:
endp
proc B
  StateHero A,foo
;...    
Post 19 Dec 2022, 22:04
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 20 Dec 2022, 05:31
This variant not for my task.
Proc B call three procs.
Proc A, proc A2, proc A3

Code:
proc A
mov edx,.Hero
call B
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp

proc A2
mov edx,.Hero
call B
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp

proc A3
mov edx,.Hero
call B
 ret
.v1 db 0
align 16
.Hero dd 0,0,0,0
         dd 0,0,0,0
.v2 dd 0
endp
    
Post 20 Dec 2022, 05:31
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1807
Roman 20 Dec 2022, 08:13
virtual not support align 16 ! fasm get error on align 16 in virtual.
Post 20 Dec 2022, 08:13
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.