flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > help me please...

Author
Thread Post new topic Reply to topic
luckystar



Joined: 23 Mar 2004
Posts: 8
luckystar
1. How to get macroinstructions parameter count?
2. How to show current line number by use "display"?
Post 07 Nov 2007, 04:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
1.
Code:
macro [a]
{
common
  count=0
  if ~ a eq   ;in case there are 0 arguments
forward
  count=count+1
common
  end if 
  ;here, "count" holds number of arguments
}    


2. you need to make some macro which converts number to ascii digits. You can download FASMLIB and take a look at src/fasmlib/display.inc. Usage of macro is described in doc/fasmlib.chm -> FASM-Specific -> disp
Post 07 Nov 2007, 05:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If for some reason you need the parameter count at preprocessing time, then you will need this code
Code:
macro name [args]
{ 
common 
local count ; In case you want to keep the count private to this macro (also valid on vid's code) 
  count equ 0 

forward 
  match c, count 
  \{ 
    rept 2 n:c \\{count equ n\\} 
  \} 

common
  match ,args\{restore count\} ; fasm executes once the forward block above when there are no args, we discount that case.

  ; Here count equate holds the number of arguments
}    


vid, but wouldn't he need Tomasz's modification to support line numbers too?
Post 07 Nov 2007, 05:54
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
another (funny) way for parameter count:
Code:
macro name [arg]
{
  common
    count equ 0
  forward
    match c, count \{
      count equ (c+1)     ; <- this instead of rept
    \}
  common
    match ,args \{ restore count \} 
    
}
    


Quote:
vid, but wouldn't he need Tomasz's modification to support line numbers too?

hmm, i thought some kind of %L is built-in, isn't it? Sad
Post 07 Nov 2007, 06:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
haha. But note that count will be usable only from assembling time as you previous code.

And no there is no such built-in (unless it is undocumented, I've just checked), but I remember that Tomasz posted how to modify fasm sources to get this feature. Where he posted it is the question Razz
Post 07 Nov 2007, 15:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7801
Location: Kraków, Poland
Tomasz Grysztar
I posted it here. Wink
Post 07 Nov 2007, 16:00
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
I have a little optimized version of your macro, vid:
Code:
macro name [arg]
{
  common
    count equ 0
  forward
    match c, count \{
      count equ c+1     ;removed the parenthesises
    \}
  common
    match ,args \{ restore count \} 
    
}
    

unfortunately, both mine and vid's version have the disadvantage of O(n^2) memory requirement if you want to count to n, which is pretty unusable.
LocoDelAssembly's version only require O(n) memory.
Post 11 Nov 2007, 23:20
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
I've never quantified memory usage Razz

Sorry to insist so much with this but I say again, vid version and yours does not make "count" usable on preprocessing time and hence both have no benefits over first vid's version.

Example:
Code:

; Supposing that my version does not make "count" local

name a, b, c

match c, count
{
  display "Output: "
  rept c \{display "^"\}
  display 13, 10
}    

Displays "Output: ^^^"

vid's version fails at " rept c \{display "^"\}" telling "invalid value" and yours for my surprise works (in the sense of no errors) but displays "Output: " only. However IMHO your version should trigger an error too so seems that you have discovered a bug!

This is the result after passing FASMPRE with your version
Code:
;match c,0+1+1+1
;{
; display 'Output: '
; rept c \{ display '^' \}
; display 13,10
;}

display 'Output: '
;rept 0+1+1+1{display '^'}
display 13,10    


However, if instead of starting with "0+" it starts with a non-zero value then it fails as expected.
Post 11 Nov 2007, 23:53
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.