flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Small proc macro extention

Author
Thread Post new topic Reply to topic
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Mostly to Tomasz.
It would be fine to preserve\restore eflags register like this:

Code:
proc LikeThis uses esi edi eflags mm0, param1:dword, param2:dword
endp
    
Post 03 Jan 2010, 12:34
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Change prologuedef macro in 'include/macro/proc32.inc' to
Code:
macro prologuedef procname,flag,parmbytes,localbytes,reglist
 { local loc
   loc = (localbytes+3) and (not 3)
   parmbase@proc equ ebp+8
   localbase@proc equ ebp-loc
   if parmbytes | localbytes
    push ebp
    mov ebp,esp
    if localbytes
     sub esp,loc
    end if
   end if
   irps reg, reglist \{ 
    if reg eq eflags
      pushfd
    else
      push reg
    end if \} }    
and epiloguedef in same file to
Code:
macro epiloguedef procname,flag,parmbytes,localbytes,reglist
 { irps reg, reglist \{ reverse 
  if reg eq eflags
    popfd
    else
    pop reg
    end if \}
   if parmbytes | localbytes
    leave
   end if
   if flag and 10000b
    retn
   else
    retn parmbytes
   end if }    
Post 03 Jan 2010, 14:48
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Another approach is to redefine push/pop to accept flags as an operand.
Code:
irp mnem, push,pop {
  macro mnem val \{
    if val eq flags
      mnem#f
    else
      mnem val
    end if
  \}
}    
Extended syntax like push eax ecx edx ebx is just one irps away.
Post 12 Jan 2010, 17:17
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:


Extended syntax like push eax ecx edx ebx is just one irps away.

But not so direct (remember expressions). However, perhaps modeling a simple state machine and accumulating symbols in an equate until it is time to issue a PUSH/POP will do it.
Post 12 Jan 2010, 20:49
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
LocoDelAssembly,

You're right, even FASM itself blunders on that (plain push 2 -1 compiles as push 1 despite explicit space; thank you, preprocessor).
Post 12 Jan 2010, 22:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
baldr wrote:
You're right, even FASM itself blunders on that (plain push 2 -1 compiles as push 1 despite explicit space; thank you, preprocessor).
Surely it is not fair to blame the preprocessor for eating the space? Perhaps instead, you should be blaming the evaluator for being greedy? Many people use the space in mathematical expressions for clarity, expecting it to be an operand separator would be hugely inconvenient.
Post 12 Jan 2010, 22:21
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution,

I forgot to insert smiley. Anyway, evaluator's greediness has nothing to do with this — look at preprocessed source.

I don't expect space to be an operand separator, FASM does. Wink
Post 12 Jan 2010, 23:14
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
baldr wrote:
revolution,

I forgot to insert smiley. Anyway, evaluator's greediness has nothing to do with this — look at preprocessed source.

I think you misunderstood him. Evaluator's greediness has very much to do with it. And the fact that the source is pre-tokenized came into design because of some other assumptions, not the opposite way.

baldr wrote:
I don't expect space to be an operand separator, FASM does. Wink

No, it does not. This one is going to be assembled without any spaces:
Code:
push(1)(2)(3)    
Not mentioning the fact, that parser/assembler doesn't even know what a "space" is - it already operates on tokens, not text.
And BTW, this PUSH/POP syntax is not something standard to fasm, it merely simulates a feature of other assembler that is frequently used.
Post 13 Jan 2010, 07:47
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Tomasz Grysztar,

I meant that evaluator has no means to detect that space was there: 2 -1 is indistinguishable from 2-1 after preprocessing. And space is essential part of push/pop specification in manual.

Pretty far off-topic, I think.
Post 13 Jan 2010, 08:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
baldr wrote:
I meant that evaluator has no means to detect that space was there: 2 -1 is indistinguishable from 2-1 after preprocessing.
As I said, this is because the evaluator doesn't need that information, not the other way around.
baldr wrote:
And space is essential part of push/pop specification in manual.

I wouldn't call it "essential". Wink It's used there because the reader is not assumed to understand the process of tokenization yet. I may consider rephrasing it, though.
Post 13 Jan 2010, 08:46
View user's profile Send private message Visit poster's website 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.