News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Echoing numeric symbols

Started by Biterider, June 22, 2019, 07:51:23 PM

Previous topic - Next topic

Biterider

Hi
Probably some of the MASM users have noticed that it is not so trivial to echo a numeric symbol. Echo writes the specified input text or, at best, the name of the symbol to the output stream, but not the value of the symbol.
The reason is quite simple; echo is designed to output plain text, what it does perfectly.

After programming workarounds for some time, I finally came up with a very pragmatic way to solve this problem. Defining a helper macro that converts the number into text makes the trick.  :icon_idea:

Example:

$ToStr macro Num
  exitm <Num>
endm

Number1 = 123
%echo This is a test using $ToStr(%Number1)


Regards, Biterider

daydreamer

Quote from: Biterider on June 22, 2019, 07:51:23 PM
Hi
Probably some of the MASM users have noticed that it is not so trivial to echo a numeric symbol. Echo writes the specified input text or, at best, the name of the symbol to the output stream, but not the value of the symbol.
The reason is quite simple; echo is designed to output plain text, what it does perfectly.

After programming workarounds for some time, I finally came up with a very pragmatic way to solve this problem. Defining a helper macro that converts the number into text makes the trick.  :icon_idea:

Example:

$ToStr macro Num
  exitm <Num>
endm

Number1 = 123
%echo This is a test using $ToStr(%Number1)


Regards, Biterider
I only played with
%echo this is a very cool game
is it good for when your source file has lots of conditional assembly
%echo This version is optimized for Px
%echo this firedemo uses palette #5 ,bluewhite fire
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

SomeTest MACRO
Local tmp$, number
  number=3
  REPEAT 5
number=number-1
tmp$ CATSTR <simple:   the num>, <ber is >, %number
% echo tmp$
if number GE 0
tmp$ CATSTR <positive: the num>, <ber is >, %number
else
tmp$ CATSTR <negative: the num>, <ber is ->, %(-number)
endif
% echo tmp$
  endm
ENDM

:wink2:

Biterider

Hi
Once you get the idea why echo is behaving this way, other solutions are also possible:


num = 123
%echo @CatStr(%num)

or

num = 123
%echo @CatStr(<num is >, %num)


:biggrin:

Biterider

daydreamer

thanks Biterider
I bet CL just removes all # in C++ #if's #elseif
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding