flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > problem: push word & byte in cinvoke

Author
Thread Post new topic Reply to topic
Blid



Joined: 19 Apr 2007
Posts: 31
Location: Russia, Novorossysk
Blid
begin....
Post 05 Aug 2007, 20:36
View user's profile Send private message Reply with quote
Blid



Joined: 19 Apr 2007
Posts: 31
Location: Russia, Novorossysk
Blid
then you push word in 32 bit mode: esp=esp-2, no esp=esp-4!
And you get wrong result = stack disbalance. To push byte is imposible at all!
I wrote this to delete this problem(word and byte). I was using the edx
register.Look:
Code:
macro cinvoke function*,[arg]
{

;this alows(very simple example):
;        cinvoke sprintf,edi,szTime,word [mytime.wYear],byte [mytime.wMonth],\
;                       dword [mytime.wDayOfWeek]
;
; it's will return correct results  '
common
local parsed_var,edx_zero,param_cntr
      edx_zero = 0
      param_cntr = 0
reverse
      parsed_var = 0
if arg eq
else
  if arg eqtype [ebp+0]
     parsed_var = 1
     push dword arg
  else
match type some,arg
\{
      parsed_var = 1

      if type in <addr,Addr,ADDR,>
   replace addr, ,Addr, ,ADDR

      lea edx,[arg]
       edx_zero =0

     restore addr,Addr,ADDR

  push edx
      end if
      if type in <b,B,byte,BYTE,Byte>

         replace b, ,byte, ,BYTE, ,Byte,

         if edx_zero <= 2
            xor edx,edx
      end if

     mov dl,arg
          edx_zero = 3

         restore b,byte,BYTE,Byte

        push edx
      end if
     if type in <word,Word,WORD,w,W>

   replace w,Word,W,Word

   if edx_zero = 0
       xor edx,edx
       end if
        mov dx,arg
          dx_zero = 2
         push edx

       restore w,W

     end if
     if type in <dword,Dword,DWORD,dw,d,D,DW,Dw>

         replace d,dword,dw,dword,D,dword,DW,dword,Dw,dword

      push  arg

       restore d,D,dw,DW,Dw
     end if
      if type eq invoke
   arg
         push eax
    edx_zero =0
      end if

\}
   end if
  if          parsed_var = 0
     push arg
  end if
end if
common
reverse
if ~arg eq
  param_cntr = param_cntr + 1
end if
common

  call [function]

  if param_cntr > 0

     if param_cntr = 2
       pop edx
     pop edx
     end if
     if param_cntr = 1
    pop edx
     end if
     if param_cntr > 2
     add esp,param_cntr*4
     end if
  end if


}
;all code had optimized by size and have some trick : ).
;play with this macros, find bug or useful properties Smile
    
Post 05 Aug 2007, 20: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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.