flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Using Structures as macro parameters

Author
Thread Post new topic Reply to topic
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 19 Oct 2004, 05:34
Hi!

Is it possible to use defined structures as macro parameters as follows:

Code:
  struc TEST x,y,color {
               .x dd x
               .y dd y
               .color dd color    
    }

macro COPY_TEST src, dst
               mov eax,dword[src.x]
               mov dword[dst.x],eax

               mov eax,dword[src.y]
               mov dword[dst.y],eax

               mov eax,dword[src.color]
               mov dword[dst.color],eax
    }


 source_test TEST 34,45,500
 dest_test   TEST 0,0,0


COPY_TEST source_test   dest_test
    


regards
Mac2004
Post 19 Oct 2004, 05:34
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 25 Oct 2004, 17:47
Code:
include '%fasminc%/win32ax.inc'

 struc TEST x,y,color {
               .x dd x
               .y dd y
               .color dd color
    }

macro COPY_TEST src,dst ;only for dword struct
{
   push  dword[src] dword[src+4] dword[src+8]
   pop   dword[dst+8] dword[dst+4] dword[dst]
}
buffer rb 32
source_test TEST 34,45,500
dest_test   TEST 0,0,0
.code

  start:
        COPY_TEST source_test,dest_test
        invoke wsprintf,buffer,'%d, %d, %d',\
                  [dest_test.x], [dest_test.y], [dest_test.color]
        invoke  MessageBox,HWND_DESKTOP,buffer,"blah blah",MB_OK
        invoke  ExitProcess,0
.end start    


for more struct elements - use that
Code:
macro COPY_TEST src,dst,nelements   ;only for dword struct
{
   repeat nelements
   push dword[src+4*%-4]
   pop  dword[dst+4*%-4]
   end repeat
}    
Post 25 Oct 2004, 17:47
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 27 Oct 2004, 07:55
Thanx Nickolay for an example! Very Happy It seemed to need a little bit more code to get it work!

regards,
Mac2004
Post 27 Oct 2004, 07:55
View user's profile Send private message Reply with quote
Klod



Joined: 25 Nov 2003
Posts: 25
Location: Canada
Klod 29 Oct 2004, 03:18
I have a similar question.
How could I load registers from a table of DWORDS for fast call with macros that have different number of elements, 1 to 6?

table:
dd 1, 10,4,6,0,100
dd 2,5,3,102,0,0
first call would load values 1,10,4,6,0,100 into regs eax,ebx,ecx,edx,esi,edi
second call would load values 2,5,3,102 to regs eax,ebx,ecx,edx etc

_________________
Do not Assume, it makes an ASS out of U and ME!
Post 29 Oct 2004, 03:18
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 08 Nov 2004, 06:46
You haven't a problem:
[table] = 1
[table+4] = 10
...
[table+28] = 2 ....
Post 08 Nov 2004, 06:46
View user's profile Send private message Reply with quote
Klod



Joined: 25 Nov 2003
Posts: 25
Location: Canada
Klod 09 Nov 2004, 02:54
What I try to do is this:
Table is a 2 dimensional table, consists of 24 bytes per record.
First dword has first byte encoded with number of elements to move, 2nd byte is not used, next to bytes are arg 1,next 4 Bytes arg 2 etc.
I’d like to the folowing (pseudo code):
Macro funcl table{
Read first byte ;determine number of elements
if element = 3
Move eax Word [table +2 ] ;arg 1
Move ebx Dword [table + 4] ;arg 2
Move ecx Dword [table + 8] ;arg 3
Call function
End if
}
If elements were 6, registers edx,edi, esi would have to be used as well.
Then I could use it like:
funcl table+ offset
Or funcl ptrThisElement etc
The problem I have is I don’t know how to build the variable arg list for the macro call

_________________
Do not Assume, it makes an ASS out of U and ME!
Post 09 Nov 2004, 02:54
View user's profile Send private message Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov 11 Nov 2004, 07:17
Code:
include '%fasminc%/win32ax.inc'

my_count  = 0
num_calls = 0
macro chg_regs table,[regs]
{
  if ~ regs eq
     forward
     mov regs,dword[table+4*my_count]
     my_count=my_count+1 ;
  end if
  common
  num_calls = num_calls + 1
  if num_calls = 2
     my_count = 0
     num_calls = 0
  end if
}

buffer rb 64
table dd 1, 10,4,6,0,100
      dd 2,5,3,102,0,0
.code
  start:
    ; first call
    chg_regs table,eax,ebx,ecx,edx,esi,edi
    invoke wsprintf,buffer,'eax=%d, ebx=%d, ecx=%d, edx=%d, esi=%d, edi=%d',\
                           eax,ebx,ecx,edx,esi,edi
    invoke  MessageBox,HWND_DESKTOP,buffer,"first call chg_regs",MB_OK
    ;second call
    chg_regs table,eax,ebx,ecx,edx
    invoke wsprintf,buffer,'eax=%d, ebx=%d, ecx=%d, edx=%d',\
                           eax,ebx,ecx,edx
    invoke  MessageBox,HWND_DESKTOP,buffer,"second call chg_regs",MB_OK
    ;third call
    chg_regs table,eax,ebx,ecx,edx,esi,edi
    invoke wsprintf,buffer,'eax=%d, ebx=%d, ecx=%d, edx=%d, esi=%d, edi=%d',\
                           eax,ebx,ecx,edx,esi,edi
    invoke  MessageBox,HWND_DESKTOP,buffer,"third call chg_regs",MB_OK
    invoke  ExitProcess,0
.end start    
Post 11 Nov 2004, 07:17
View user's profile Send private message Reply with quote
Klod



Joined: 25 Nov 2003
Posts: 25
Location: Canada
Klod 16 Nov 2004, 03:09
Thanks for your help Nickolay:
This is not quite what I was looking for.
I did this:

macro funcl ptr
{
cnt db 1
local end
mov ebx, dword[ptr+4]
inc [cnt]
cmp [ptr+0],cnt
jpe end
mov ecx, dword[ptr+8]
inc [cnt]
cmp [ptr+0],cnt
jpe end
mov edx, dword[ptr+12]
inc [cnt]
; cmp [ptr+0],cnt
; jpe end
; mov edi, dword[ptr+16]
inc [cnt]
; cmp [ptr+0],cnt
; jpe end
; mov esi, dword[ptr+20]

end:
mov ax, word [ptr+2]
call int 40
}

This is not very pretty however

I found these macros on the Menuet thread:

macro mcall a,b,c,d,e,f { ; mike.dld
__mov eax,a
__mov ebx,b
__mov ecx,c
__mov edx,d
__mov esi,e
__mov edi,f
int 0x40
}

macro __mov reg,a,b { ; mike.dld
if (~a eq)&(b eq)
mov reg,a
end if
}

How could I build the arg list in a Macro to take advantage of these macros?
Pseudo code:
macro funcl ptr
{
argcnt word [ptr+2] ;count = 1 to 6 depending on function called
arg1 dd [ptr+4]
argn dd [ptr+n]
….
Arglist[arg1,arg2…,argn] ;arglist varies 1 to 6 args depending on argcnt
Mcall arglist
}

The move macro would have to be modified to accept memops.
With tis stile of programming I hope to make function calls using arguments from tables or structures.
funcl pointr
funcl struc

Could you help me with this?

_________________
Do not Assume, it makes an ASS out of U and ME!
Post 16 Nov 2004, 03:09
View user's profile Send private message Reply with quote
Klod



Joined: 25 Nov 2003
Posts: 25
Location: Canada
Klod 18 Nov 2004, 02:44
I just red my post.
I have some typos:
All those jpe instructions shoul read je
macro __mov reg,a {
if ~a eq
mov reg,a
end if
}
argcnt word [ptr+0] ;count = 1 to 6 depending on function called
I typed it all out of memory after work, must have been very tiered Embarassed

_________________
Do not Assume, it makes an ASS out of U and ME!
Post 18 Nov 2004, 02:44
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.