flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Please help: JE ret

Author
Thread Post new topic Reply to topic
wht36



Joined: 18 Sep 2005
Posts: 106
wht36 04 Sep 2006, 16:14
Sorry, I am new to macro programming... In the old days when I was using A86, I could put something like

Code:
         cmp al,0
         je   ret
         ...
         ret    


and the assembler would automatically generate a jump to the nearest return. Now is it possible to use make a macro to do something similar in FASM?

The closest I've come to is
Code:
macro ret
{ if ~ defined .ret | defined @f
  .ret:
  @@: ret
  end if }
...
     cmp al,0
     je .ret
     ...
     ret    

So is this the way to do it?

Going off on a tangent, must I use commas between the parameters of a macro e.g. push ax,bx,cx,dx instead of push ax bx cx dx?
Post 04 Sep 2006, 16:14
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 04 Sep 2006, 16:52
Quote:
Going off on a tangent, must I use commas between the parameters of a macro e.g. push ax,bx,cx,dx instead of push ax bx cx dx?

No, push 0h esi 0h edi seems to be working
Post 04 Sep 2006, 16:52
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Sep 2006, 19:26
1. there is no "ret" isntruction, i believe you mean "retn". "ret" is pseudo-opcode (macro in FASM) to return from current context (eg. procedure)

to your problem: you may find way to solution here
Post 04 Sep 2006, 19:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 04 Sep 2006, 23:54
Yes, there is the "ret" instruction. In fact, it is not an instruction, but not implemented as a macro.
Post 04 Sep 2006, 23:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 05 Sep 2006, 01:36
But it's true that "ret" is implemented as a macro in PROC context.
Post 05 Sep 2006, 01:36
View user's profile Send private message Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36 05 Sep 2006, 05:47
Hmm, so ret is not an instruction... does that mean if I try to implement my ret macro something nasty would happen and I should just use something like jmp @f instead of jmp .ret?

Sigh... what a pity, I thought something like JMP RET would be much clearer than JMP @F
Post 05 Sep 2006, 05:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 05 Sep 2006, 07:33
i think tomasz explained it somewhere, that ret should be return from current context, it's not defined in manuals (not sure about this), and implemented "ret"="retn" for compatibility with other assemblers, and because people ought to use it.

those @@@/@@f/@@b macros showed you way how you can solve your problem with macros. analogy, overload "ret" with something like "@@@", and overload "jmp ret" with something that compares distance to neares preceding ret (@@b) and nearest following ret (@@f). Of course you need more checks (no preceding/following ret) etc.
Post 05 Sep 2006, 07:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36 07 Dec 2010, 15:31
Not fully tested, but I think one can simulate JE ret, jb ret4 etc with the macros below
Code:
irp cond, mp, a, b, be, c, e, l, le, o, s, z, na, nb, nbe, nc, ne, nl, nle, no, ns, nz {
   macro j#cond addr { 
      j equ addr
      match =ret,addr { j equ ..ret \\}
      match =ret4,addr { j equ ..ret4 \\}
      match =ret8,addr { j equ ..ret8 \\}
      match =ret12,addr { j equ ..ret12 \\}
      j#cond j
   \}
}

macro ret n {                           ; macro to create a label for each ret instruction so one can use e.g. jmp .ret4 & je .ret
   match =..ret#n,..ret#n {..ret#n:\}  ; create the label .ret if .ret was not defined previously so that forward jumps to .ret will work
   local ..z                              ; create anonymous label ..z for each ret
   ..z: ret n                          ; make the anonymous label specific to n
   match ,n { ..ret equ ..z \}           ; assign the label to .ret if there is no n specified
   match x,n { ..ret\#x equ ..z \} ; else assign .retn to the label
}
    
Post 07 Dec 2010, 15:31
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.