The MASM Forum

General => The Campus => Topic started by: megavlad on May 04, 2025, 09:11:00 AM

Title: How to use the 'echo' command in MASM
Post by: megavlad on May 04, 2025, 09:11:00 AM
I'm using MASM in MSVC 2022, Windows 10. I'm coding in 64bit mode, only.

I'm learning from an assembly book that uses MASM. In there, it mentions the 'echo' command can be used to output compile-time messages. I tried adding it to my sample code, but I don't see the message in the MSVC output window.

I don't get an error, just nothing gets printed.

Is there something that needs to be enabled to support it?

Thanks
Title: Re: How to use the 'echo' command in MASM
Post by: NoCforMe on May 04, 2025, 09:30:57 AM
echo is used in batch files. You know, the command files that are run from the Windows (or DOS if you're going back that far) command window. It displays to the command window:

@echo off

ml /c /coff /Fl /Sn %1.asm
if errorlevel 1 goto errasm

link /SUBSYSTEM:WINDOWS %1
if errorlevel 1 goto errlink

dir %1.*
goto TheEnd

:errlink
echo _
echo Link error
goto TheEnd

:errasm
echo _
echo Assembly Error

:TheEnd

It has nothing to do with assembly-langauge code.
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 04, 2025, 09:37:51 AM
Quote from: NoCforMe on May 04, 2025, 09:30:57 AMIt has nothing to do with assembly-langauge code.

https://learn.microsoft.com/en-us/cpp/assembler/masm/echo?view=msvc-170 (https://learn.microsoft.com/en-us/cpp/assembler/masm/echo?view=msvc-170)
Title: Re: How to use the 'echo' command in MASM
Post by: NoCforMe on May 04, 2025, 10:44:41 AM
Whoops, my bad. Forgot about that echo.

You say you're using Visual C, right? It must have something to do with how that IDE handles output from the assembler. You might have to set a switch or something.

Someone who knows more about this than I do should be along shortly to help you ...
Title: Re: How to use the 'echo' command in MASM
Post by: Quin on May 04, 2025, 09:34:22 PM
Definitely a problem with msvc...
This works flawlessly with QEditor and the MASM32 SDK.
.386
.model flat, stdcall
option casemap: none

.code
start:
    echo This is a test
end start
I see
QuoteThis is a test
right after the
QuoteAssembling: C:\Users\Quin\git\test.asm
line.
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 12:02:30 AM
Quote from: Quin on May 04, 2025, 09:34:22 PM.386
.model flat, stdcall

Thanks for checking the 32bit version. Are you able to check if the 64bit version also works?
Title: Re: How to use the 'echo' command in MASM
Post by: Quin on May 05, 2025, 12:49:40 AM
Yup, works in 64-bit, too. :)
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 01:12:18 AM
Quote from: Quin on May 05, 2025, 12:49:40 AMYup, works in 64-bit, too. :)

Cool. If you don't mind, can you please show the exact snipped that you used for testing?

ChatGPT says that it's not supported in 64bit, but ChatGPT often lies.
Since you got it to work, I would use your test as working base, and fiddle with the IDE settings.

Thanks
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 01:16:12 AM
Quote from: megavlad on May 05, 2025, 01:12:18 AMChatGPT says that it's not supported in 64bit, but ChatGPT often lies.
The results from ChatGPT or any other AI must always be tested and/or verified. I have learned that very early on in my experimentation using AI for assembly code, as well as C code.
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 01:28:59 AM
Quote from: megavlad on May 05, 2025, 01:12:18 AM
Quote from: Quin on May 05, 2025, 12:49:40 AMYup, works in 64-bit, too. :)

Cool. If you don't mind, can you please show the exact snipped that you used for testing?
I was curious, so I tested it myself: Nevermind what ChatGPT says regarding this... :biggrin:

(https://i.postimg.cc/3N3zjdXg/untitled.png)
yurp, it werks!

The code I used...
include \masm64\include64\masm64rt.inc

.data

.code

start proc

    echo Testing 1, 2, 3...
    invoke ExitProcess, 0
   
start endp

end

Batch file to assemble and link:
@echo off
SET asm="test64"
if exist %asm%.exe del %asm%.exe

\masm64\bin64\ml64 /c /nologo %asm%.asm
if errorlevel 1 goto paws

\masm64\bin64\Link /subsystem:windows /entry:start /nologo %asm%.obj
if errorlevel 1 goto paws

del *.obj

pause

Since I do not use Visual Studio or other "Visual" IDE, I viewed the command prompt output...
Title: Re: How to use the 'echo' command in MASM
Post by: Quin on May 05, 2025, 01:58:20 AM
You're faster than me Zedd :D
I step away to brew my coffee and you've answered a question someone had for me. Wizard!  :biggrin:
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 02:00:53 AM
Quote from: Quin on May 05, 2025, 01:58:20 AMYou're faster than me Zedd :D
I step away to brew my coffee and you've answered a question someone had for me. Wizard!  :biggrin:
Actually I hate writing in 64 bit. But I was also curious as well, so I tested it.

Yes there is an echo in here.  :eusa_dance:
I am hardly a wizard though.  :cool:
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 02:36:02 AM
Quote from: zedd on May 05, 2025, 01:28:59 AMSince I do not use Visual Studio or other "Visual" IDE, I viewed the command prompt output...

Thanks for verifying. I tried your example from the command line as well, and indeed it prints the message. Since that is a compile-time directive, the test can be reduced further to:

In assembly test file "test.asm":

echo Testing 1, 2, 3...
end


In command line:

ml64 /c test.asm



Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 02:54:12 AM
Quote from: megavlad on May 05, 2025, 02:36:02 AMSince that is a compile-time directive, the test can be reduced further to:
Of course you are correct. I was using a ready-made template (as-is) for testing.
Title: Re: How to use the 'echo' command in MASM
Post by: NoCforMe on May 05, 2025, 04:14:54 AM
Quote from: megavlad on May 05, 2025, 02:36:02 AM
Quote from: zedd on May 05, 2025, 01:28:59 AMSince I do not use Visual Studio or other "Visual" IDE, I viewed the command prompt output...

Thanks for verifying. I tried your example from the command line as well, and indeed it prints the message. Since that is a compile-time directive, the test can be reduced further to:

In assembly test file "test.asm":

echo Testing 1, 2, 3...
end

In command line:

ml64 /c test.asm

So were you able to solve your MSVC problem?
That would be useful info for others who use that IDE.
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 04:17:49 AM
Quote from: NoCforMe on May 05, 2025, 04:14:54 AMSo were you able to solve your MSVC problem?

No, I haven't. The test code outputs the message from the command line. When testing within the IDE, there is no message to the output pane.
Title: Re: How to use the 'echo' command in MASM
Post by: Quin on May 05, 2025, 05:33:08 AM
Quote from: megavlad on May 05, 2025, 04:17:49 AM
Quote from: NoCforMe on May 05, 2025, 04:14:54 AMSo were you able to solve your MSVC problem?

No, I haven't. The test code outputs the message from the command line. When testing within the IDE, there is no message to the output pane.
I wonder if the IDE's output pane is grabbing stdout and just dropping it on the floor? From what I can tell, echo prints to stdout.
I haven't used visual studio in years, but what if you try echoing text like this?
Quoteecho test.asm(1) : Hello from MASM!
adjust it to be formatted how your visual studio actually outputs warnings/errors/etc.
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 06:00:15 AM
Quote from: Quin on May 05, 2025, 05:33:08 AM... what if you try echoing text like this?

echo test.asm(1) : Hello from MASM!

I'm not following. Do you mean to insert that literally in the code? I tried it on the command line and it just outputs that literal string. From the IDE, still doesn't work.
Title: Re: How to use the 'echo' command in MASM
Post by: sinsi on May 05, 2025, 07:22:58 AM
The only way I could get the assembler to echo anything was from a terminal window (right-click project).
Output and Immediate windows show nothing.
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 07:27:15 AM
Quote from: sinsi on May 05, 2025, 07:22:58 AMThe only way I could get the assembler to echo anything was from a terminal window (right-click project).
Output and Immediate windows show nothing.
Maybe there is a setting, option, or flag to enable using it?
How about with 32 bit code, does it work then? Perhaps ChatGPT was correct in certain contexts/usage of 'echo'.

I thought it (Visual xxx IDE) was using the output of StdOut.
Title: Re: How to use the 'echo' command in MASM
Post by: Quin on May 05, 2025, 07:58:51 AM
Quote from: megavlad on May 05, 2025, 06:00:15 AM
Quote from: Quin on May 05, 2025, 05:33:08 AM... what if you try echoing text like this?

echo test.asm(1) : Hello from MASM!

I'm not following. Do you mean to insert that literally in the code? I tried it on the command line and it just outputs that literal string. From the IDE, still doesn't work.
Don't worry about it, it was a very naive possible workaround, I thought if you formatted text sent to stdout like an error message/other message from the assembler it might not get dropped by VS when echoing, but I guess not. Was worth a shot I suppose.
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 08:01:42 AM
How about ensuring 'echo' is actually on first?


echo on
echo This is Echoed

Another try at a naive workaround.  :biggrin:

I might have to download it myself to try to find a solution...

megavlad, you say you are using MSVC. (IDE I assume.)

What is the actual name of the IDE itself?  I had never heard of MSVC other than Microsoft Visual C.  Probably can get that from the about box.
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 08:57:45 AM
Quote from: zedd on May 05, 2025, 08:01:42 AMWhat is the actual name of the IDE itself?  I had never heard of MSVC other than Microsoft Visual C.  Probably can get that from the about box.

MSVC is the common abbreviation of "Microsoft Visual C++". I use the latest community version: 2022
Title: Re: How to use the 'echo' command in MASM
Post by: sinsi on May 05, 2025, 08:58:04 AM
@zedd, in this context ECHO is a MASM directive and has nothing to do with a batch file.

There is one way of getting it to show in the Output window but it's a bit crap :biggrin:
QuoteTools->Options->Projects and Solutions->Build and Run
From the "MSBuild project build output verbosity" dropdown box, choose the "Detailed" option
Unfortunately you have to scroll through pages of output (over 1000 lines) to see it, although you can control-f and find it, so you might want to use a keyword to search for.
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 09:01:25 AM
Quote from: sinsi on May 05, 2025, 08:58:04 AM@zedd, in this context ECHO is a MASM directive and has nothing to do with a batch file.
Yes, I realize that. I always use a batch file to assemble my projects though. Easiest way too, to see the output.  :biggrin:

I just wanted to test whether 'echo' worked while using ml64. Mission accomplished.

As far as the setting being buried, that doesn't surprise me.
Title: Re: How to use the 'echo' command in MASM
Post by: zedd on May 05, 2025, 09:04:39 AM
Quote from: megavlad on May 05, 2025, 08:57:45 AMMSVC is the common abbreviation of "Microsoft Visual C++". I use the latest community version: 2022
Okay. You use Visual C++, and its IDE. As opposed to Visual Studio, or Visual Code... or whatever other names they use now.

Anyway, I don't think I'll be downloading any of them any time soon.  :biggrin:
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 09:12:52 AM
Quote from: sinsi on May 05, 2025, 08:58:04 AMThere is one way of getting it to show in the Output window but it's a bit crap :biggrin:
QuoteTools->Options->Projects and Solutions->Build and Run
From the "MSBuild project build output verbosity" dropdown box, choose the "Detailed" option
Unfortunately you have to scroll through pages of output (over 1000 lines) to see it, although you can control-f and find it, so you might want to use a keyword to search for.



Earlier, when I was searching for a fix, I came a across a similar suggestion from this site:
https://www.codeproject.com/articles/1080585/something-you-may-not-know-about-the-macro-in-masm

That author is using MASM32. But, I did try it myself but it didn't work for 64bit.

In your case, were you able to actually get it to show up on the output, or are you speculating?
Title: Re: How to use the 'echo' command in MASM
Post by: sinsi on May 05, 2025, 09:47:52 AM
Untitled.png
Title: Re: How to use the 'echo' command in MASM
Post by: megavlad on May 05, 2025, 09:57:23 AM
I tried the same code as you, with various output levels, but nothing. Weird.

Thanks for confirming.