Author Topic: Echoing numeric symbols  (Read 534 times)

Biterider

  • Member
  • ***
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Echoing numeric symbols
« 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:

Code: [Select]
$ToStr macro Num
  exitm <Num>
endm
 
Number1 = 123
%echo This is a test using $ToStr(%Number1)

Regards, Biterider
« Last Edit: June 22, 2019, 10:30:52 PM by Biterider »

daydreamer

  • Member
  • ****
  • Posts: 942
  • watch Chebyshev on the backside of the Moon
Re: Echoing numeric symbols
« Reply #1 on: June 22, 2019, 11:31:54 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:

Code: [Select]
$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
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D

jj2007

  • Member
  • *****
  • Posts: 9794
  • Assembler is fun ;-)
    • MasmBasic
Re: Echoing numeric symbols
« Reply #2 on: June 23, 2019, 02:31:20 AM »
Code: [Select]
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

  • Member
  • ***
  • Posts: 392
  • ObjAsm32 + ObjAsm64 = ObjAsm
    • ObjAsm
Re: Echoing numeric symbols
« Reply #3 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:

Code: [Select]
num = 123
%echo @CatStr(%num)
or
Code: [Select]
num = 123
%echo @CatStr(<num is >, %num)

 :biggrin:

Biterider

daydreamer

  • Member
  • ****
  • Posts: 942
  • watch Chebyshev on the backside of the Moon
Re: Echoing numeric symbols
« Reply #4 on: June 23, 2019, 03:52:35 AM »
thanks Biterider
I bet CL just removes all # in C++ #if's #elseif
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D