flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > fasm1 proc - not accurate handling of ebp frame needance

Thread Post new topic Reply to topic

Joined: 24 Mar 2012
Posts: 786
Location: Russian Federation, Sochi
ProMiNick 22 Jun 2022, 14:33
official macro set breaks paradigm of producing minimal possible code
There is no matter present args & locals or not. Only matter used they or not.
Test sequence:
proc test arg1,arg2
        a dd ?
        xor     eax, eax

how to fix proc32.inc for proper handling?
1) replace condition "parmbytes | localbytes" with "used@frame" in prologuedef & epiloguedef macros pass that condition via macro args.
2) Also make used@frame as local for macro define@proc because outside of proc using it is unusable.
3) In every proc used@frame is setted only once in finish@proc macro by assignig final value of global used@frame@test: used@frame = used@frame@test
4) before handling of args (before using macro prologue) we initialize used@frame@test: used@frame@test = 0
5) then we make accumulation of used@frame@test if any arg or local var used in proc - we doing that in 2 macros:
for every arg of defargs@proc (for every - in any forward block)
if used ..arg
        used@frame@test = 1
     end if    

for every local defined with deflocal@proc macro (here in common block because forwarding goes via values of current local)
if used name
        used@frame@test = 1
     end if    

affected pieces:
macro prologuedef procname,flag,used@frame,parmbytes,localbytes,reglist ; patch line
 { local loc
   loc = (localbytes+3) and (not 3)
   parmbase@proc equ ebp+8
   localbase@proc equ ebp-loc
   if used@frame ; patch line
    push ebp
    mov ebp,esp
    if localbytes
     sub esp,loc
    end if
   end if
   irps reg, reglist \{ push reg \} }
macro epiloguedef procname,flag,used@frame,parmbytes,localbytes,reglist ; patch line
 { irps reg, reglist \{ reverse pop reg \}
   if used@frame ; patch line
   end if
   if flag and 10000b
    retn parmbytes
   end if }
macro define@proc name,statement
 { local params,flag,regs,parmbytes,localbytes,current,used@frame ; patch line
   match =regs, regs \{ regs equ \}
   used@frame@test = 0 ; patch line
   match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,used@frame,parmbytes,localbytes,reglist \} ; patch line
      match , operand \\{ match epilogue:reglist, epilogue@proc:<regs> \\\{ epilogue name,flag,used@frame,parmbytes,localbytes,reglist \\\} \\} \} ; patch line
   macro finish@proc
   \{ localbytes = current
      used@frame = used@frame@test ; patch line
      match close:reglist, close@proc:<regs> \\{ close name,flag,parmbytes,localbytes,reglist \\}
      end if \} } 
macro defargs@proc [arg]
 { common
    if ~ arg eq
     local ..arg,current@arg
     match argname:type, arg
      \{ current@arg equ argname
         label ..arg type
         argname equ ..arg
         if qqword eq type
           dd ?,?,?,?,?,?,?,?
         else if dqword eq type
           dd ?,?,?,?
         else if tbyte eq type
           dd ?,?,?
         else if qword eq type | pword eq type
           dd ?,?
           dd ?
         end if \}
     match =current@arg,current@arg
      \{ current@arg equ arg
         arg equ ..arg
         ..arg dd ? \}
     if used ..arg  ; patch line
        used@frame@test = 1  ; patch line
     end if  ; patch line
     args@proc equ current@arg
     restore current@arg
    end if }
macro deflocal@proc name,def,[val]
 { common
    match vars, all@vars \{ all@vars equ all@vars, \}
    all@vars equ all@vars name
    local ..var,..tmp
    ..var def val
    match =?, val \{ ..tmp equ \}
    match any =?, val \{ ..tmp equ \}
    match any (=?), val \{ ..tmp equ \}
    match =label, def \{ ..tmp equ \}
    match tmp : value, ..tmp : val
     \{ tmp: end virtual
        initlocal@proc ..var,def value
        virtual at tmp\}
    match first rest, ..var, \{ name equ first \}
     if used name  ; patch line
        used@frame@test = 1  ; patch line
     end if                      } ; patch line    

I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 22 Jun 2022, 14:33
View user's profile Send private message Send e-mail 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.