The MASM Forum

General => The Laboratory => Topic started by: Biterider on June 22, 2019, 07:51:23 PM

Title: Echoing numeric symbols
Post by: 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
Title: Re: Echoing numeric symbols
Post by: daydreamer on June 22, 2019, 11:31:54 PM
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
Title: Re: Echoing numeric symbols
Post by: jj2007 on June 23, 2019, 02:31:20 AM
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:
Title: Re: Echoing numeric symbols
Post by: Biterider on June 23, 2019, 02:50:22 AM
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
Title: Re: Echoing numeric symbols
Post by: daydreamer on June 23, 2019, 03:52:35 AM
thanks Biterider
I bet CL just removes all # in C++ #if's #elseif