Hey all...
I'm trying to figure out how to use macros with complex data structures and I'm having some trouble.... what I want to do is I have a structure:
struc myval
{
.ptr dd ?
.dtype db ?
}
which contains a pointer to a block of memory (from my memory manager) and its data type. I wanted to write a macro that creates a "reference" to one of these variables:
macro makeref var1, var2
{
push eax
mov eax,
mov , eax
mov eax,
mov , eax
ccall mm_make_ref,
pop eax
}
However, when i try to use this macro it dies on me assembly:
makeref
I can't seem to figure out how this works. It seems to me that I can't use these sorts of things with strucs! How could I implement such a thing in FASM? Any clues?
John
I'm trying to figure out how to use macros with complex data structures and I'm having some trouble.... what I want to do is I have a structure:
struc myval
{
.ptr dd ?
.dtype db ?
}
which contains a pointer to a block of memory (from my memory manager) and its data type. I wanted to write a macro that creates a "reference" to one of these variables:
macro makeref var1, var2
{
push eax
mov eax,
mov , eax
mov eax,
mov , eax
ccall mm_make_ref,
pop eax
}
However, when i try to use this macro it dies on me assembly:
makeref
I can't seem to figure out how this works. It seems to me that I can't use these sorts of things with strucs! How could I implement such a thing in FASM? Any clues?
John
See if this help.
struc myval
{
ptr dd ? <--- No .
dtype db ? <--- No .
}
macro makeref var1, var2
{
push eax
mov eax,
mov , eax
mov eax, <-- var1 was var2
mov , eax
ccall mm_make_ref,
pop eax
}
struc myval
{
ptr dd ? <--- No .
dtype db ? <--- No .
}
macro makeref var1, var2
{
push eax
mov eax,
mov , eax
mov eax, <-- var1 was var2
mov , eax
ccall mm_make_ref,
pop eax
}
ARG!
These macros are SO FRUSTERATING.
macro ccall proc, ; call procedure
{ common local size
size = 0
reverse
pushd arg
size = size+4
common
call proc
add esp,size }
macro dbg_printf {
{ common ccall printf, arg }
That SHOULD work, right? I mean I almost stole it right out of the manual, I should be able to call it:
dbg_printf __DBGMSG, ecx
where __DBGMSG:
__DBGMSG db "Myvar: %d", 0xA, 0
But it gives me an error:
dbgprintf __PASM_DBGMSG_MMDEST, ecx
error: illegal instruction.
What gives with this... I just don't understand what's the difference between the macros that came with FASM and mine... other than mine have yet to work once.
John
These macros are SO FRUSTERATING.
macro ccall proc, ; call procedure
{ common local size
size = 0
reverse
pushd arg
size = size+4
common
call proc
add esp,size }
macro dbg_printf {
{ common ccall printf, arg }
That SHOULD work, right? I mean I almost stole it right out of the manual, I should be able to call it:
dbg_printf __DBGMSG, ecx
where __DBGMSG:
__DBGMSG db "Myvar: %d", 0xA, 0
But it gives me an error:
dbgprintf __PASM_DBGMSG_MMDEST, ecx
error: illegal instruction.
What gives with this... I just don't understand what's the difference between the macros that came with FASM and mine... other than mine have yet to work once.
John
Try this one:
macro makeref var1, var2
{
push eax
mov eax, [var1#.ptr]
mov [var2#.ptr], eax
mov al, [var2#.dtype]
mov [var2#.dtype], al
ccall mm_make_ref, [var1#.ptr]
pop eax
}
a myval
b myval
makeref a,b
Thanks. I ended up getting some macros working the way I wanted them to using virtual instead of strucs, but you better believe I'll be bookmarking this thread so I can see how that works again :)
My big issue now is trying to get a float to work... For some reason, this code doesn;t work (Linux ELF)
myfloat dd 1234.34f
pfloat db "Float Value: %f",0
...
ccall printf, pfloat,
The result:
Float Value: 0.000000
I must be missing something really obvious.
John
My big issue now is trying to get a float to work... For some reason, this code doesn;t work (Linux ELF)
myfloat dd 1234.34f
pfloat db "Float Value: %f",0
...
ccall printf, pfloat,
The result:
Float Value: 0.000000
I must be missing something really obvious.
John