flat assembler
Message board for the users of flat assembler.

Index > Main > Short help with glcall macro

Author
Thread Post new topic Reply to topic
Hotwire



Joined: 17 Sep 2015
Posts: 5
Hotwire
Hello!

I found this macro in some of the tutorials on this site long time ago
Code:
macro pushdl double
{
fild qword [double]
sub esp,8
fstp qword [esp]
}
macro glpushv GLfloatVar
{
push dword [GLfloatVar+4]
push dword [GLfloatVar]
}
macro glpush GLfloatVar
{
name = GLfloatVar
virtual at 0
dq GLfloatVar
load name#.l dword from 0
load name#.h dword from 4
end virtual
if name.h=0
push ebx
else
push dword name.h
end if
if name.l=0
push ebx
else
push dword name.l
end if
}
macro glcall procedure,[arg]
{
reverse
if arg eqtype 1.0
glpush arg
else
if arg eqtype eax
push arg
else
addr=arg
glpushv addr
end if
end if
common
call dword [procedure]
}
    


However fasm returns an error when I try to write something like this
Code:
push GL_BLEND
glcall glEnable
    

How should I modify the macro to avoid this error?

If someone can provide a good manual on fasm macrolanguage I would greatly appreciate this.
Post 12 Sep 2021, 19:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18222
Location: In your JS exploiting you and your system
revolution
What error do you get?

Is it from push or glcall line?
Post 12 Sep 2021, 19:13
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
Hotwire wrote:
However fasm returns an error when I try to write something like this
Code:
push GL_BLEND
glcall glEnable    

try that
Hotwire wrote:

macro glcall procedure,[arg]
{
common if ~ arg eq
reverse
if arg eqtype 1.0
glpush arg
else
if arg eqtype eax
push arg
else
addr=arg
glpushv addr
end if
end if
common end if
call dword [procedure]
}

https://flatassembler.net/docs.php?article=manual#2.3.3
Post 12 Sep 2021, 19:19
View user's profile Send private message Reply with quote
Hotwire



Joined: 17 Sep 2015
Posts: 5
Hotwire
Quote:

Is it from push or glcall line?

From glcall line
Code:
 addr=arg
error: invalid value
    


Quote:

try that

Now fasm returns
Code:
 error: illegal instruction     

on glcall line
Post 13 Sep 2021, 06:52
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
Hotwire wrote:

Now fasm returns
Code:

 error: illegal instruction     

    

on glcall line

documentation wrote:

If the error is connected with a specific part of source code, the source line that caused the error will be also displayed. Also placement of this line in the source is given to help you finding this error, for example:
Code:
flat assembler  version 1.73 (16384 kilobytes memory)
example.asm [3]:
        mob     ax,1
error: illegal instruction.
    

It means that in the third line of the example.asm file compiler has encountered an unrecognized instruction. When the line that caused error contains a macroinstruction, also the line in macroinstruction definition that generated the erroneous instruction is displayed:
Code:
flat assembler  version 1.73 (16384 kilobytes memory)
example.asm [6]:
        stoschar 7
example.asm [3] stoschar [1]:
        mob     al,char
error: illegal instruction.
    

It means that the macroinstruction in the sixth line of the example.asm file generated an unrecognized instruction with the first line of its definition.


maybe

Hotwire wrote:
macro glcall procedure,[arg]
{
common if ~ arg eq
reverse
if arg eqtype 1.0
glpush arg
else
if arg eqtype eax
push arg
else
addr=arg
glpushv addr
end if
end if
common end if
call dword [procedure] ; <- -- -- --
}
or did you delete the macros glpush and glpushv for some reason, which I did not suggest removing, but simply adding two lines to the macro glcall
Post 13 Sep 2021, 10:34
View user's profile Send private message Reply with quote
Hotwire



Joined: 17 Sep 2015
Posts: 5
Hotwire
macomics
Thanks for the help. I've really messed up with compiling I was changing the wrong file. Now it works perfectly. However I would like to like to ask several associated questions
1) Added lines to the code of glcall macro simply checks if there are any arguments at all?
2) Could you please explain the line addr=arg ? It looks like it simply renames arg to addr Am I allowed to write simply glpushv arg I've tried on some examples, everything works but I wonder if this line was introduced for pure convenience or really means something conceptually?
Post 13 Sep 2021, 17:16
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
Hotwire wrote:
1) Added lines to the code of glcall macro simply checks if there are any arguments at all?
Yes.
Hotwire wrote:
2) Could you please explain the line addr=arg ? It looks like it simply renames arg to addr Am I allowed to write simply glpushv arg I've tried on some examples, everything works but I wonder if this line was introduced for pure convenience or really means something conceptually?
https://flatassembler.net/docs.php?article=manual#2.2.1 wrote:
2.2.1 Numerical constants

The = directive allows to define the numerical constant. It should be preceded by the name for the constant and followed by the numerical expression providing the value. The value of such constants can be a number or an address, but - unlike labels - the numerical constants are not allowed to hold the register-based addresses. Besides this difference, in their basic variant numerical constants behave very much like labels and you can even forward-reference them (access their values before they actually get defined).
Simply put, with this line, they get rid of determining the size of the variable at the label.
Code:
  glpushv qword value

value      dd ?, ?

; then addr = qword value equal to addr = value and then
;  push dword [addr+4]  ; instead push dword [qword label + 4]  <- incorrect
;  push dword [addr+0]  ; instead push dword [qword label + 0]  <- incorrect
    


ADD: You can also add something else to your macro
Quote:
macro glpushrv raddr
{
local ..test ; local name
..test equ TRUE ; define a symbolic constant
match qword [rel+off], raddr \{ ; check raddr like qword [ecx+1]
push dword [rel+off+4] ; reassemble the argument in the form of "dword [ecx+1+4]"
push dword [rel+off+0] ; reassemble the argument in the form of "dword [ecx+1+0]"
restore ..test ; restore const value, now ..test is undefined
\}
; only if match has worked, the value ..test will be undefined
match =TRUE, ..test \{ push raddr \} ; If the value is still defined, the following line will work -> push dword [ecx+1]
restore ..test ; restore const value, now ..test is undefined (clear)
}

macro glcall procedure,[arg]
{
common if ~ arg eq
reverse
if arg eqtype 1.0
glpush arg
else if arg eqtype eax ; "arg like register"
push arg ; simple command
else if arg relativeto ecx ; arg like "dword [ecx+const]", you can add more "if ..."
glpushrv arg ; apply a new macro for this argument type
else if arg relativeto ebx ; the same thing, but for ebx
glpushrv arg ; apply a new macro for this argument type
else ; otherwise "arg like [label_name]"

addr=arg
glpushv addr
end if
common end if
call dword [procedure]
}


ADD: Oops. I forgot about my own old fixes.


Last edited by macomics on 14 Sep 2021, 21:15; edited 2 times in total
Post 13 Sep 2021, 17:25
View user's profile Send private message Reply with quote
Hotwire



Joined: 17 Sep 2015
Posts: 5
Hotwire
macomics
I really appreciate your help but could you add some comments to your code. I am completely fine with assembly but I am not used to macro language of fasm yet.
Post 14 Sep 2021, 20:10
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
add. see above
Post 14 Sep 2021, 21:14
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.