flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > String length

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
How can I count length of string?
I want to show message with dashed lines around.

I came up with this method:
Code:
macro   @error_msg      text
{
  local .strlen
  virtual at 0
    db text
    .strlen = $
  end virtual
  repeat .strlen
    display '-'
  end repeat
  display 10,text,10
  repeat .strlen
    display '-'
  end repeat
  err
}    


Maybe there are others (shorter)? Smile
Post 25 Dec 2020, 18:36
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 952
Location: Belarus
DimonSoft
What is your real goal? Are you displaying hyphens for debugging purposes or decorate the output?

If the string shouldn’t be put into the output file, your solution is quite good. The only thing I’d probably avoid is single-dot-prefixing the identifier, just in case some day I expand the macro to do more (since it might be prefixed with the nearest preceding global label name).

P.S. Well, maybe you could make the hyphen printing a separate macro with (two?) parameters. I don’t know if it’s worth doing for your project.
Post 26 Dec 2020, 08:01
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.