Author Topic: Error -'nasm' is not recognized as an internal or external command, operable....  (Read 3486 times)

Offline chris.

  • Jr. Member
  • *
  • Posts: 2
I am learning assembly and decided to start by following this guide (http://ccm.net/faq/1559-compiling-an-assembly-program-with-nasm#step-1-install-the-necessary-
software
)

I got to step three (windows) after creating the test.asm file and get the error: "'nasm' is not recognized as an internal or external command,
operable program or batch file." whenever I try to run "nasm -f win32 test.asm -o test.o".

Please help I am lost. I have followed the steps in the guide, but cant get past step three for windows.


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2358
  • Country: us
Hi Chris,
Welcome to the Forum.

The problem you have encountered is not, strictly speaking a "Nasm problem" but an "operating system problem". It appears that Nasm is not on your "path". The "path", if you don't know, is a list of directories (folders) that the OS searches for executable files. I would expect that if you followed your "guide", the process of installing MinGW would have put "C:\MinGW\bin" on your "path". Apparently not.

At one time, Windows provided an extensive help system. If you typed "help path" it would tell you more than you wanted to know. That may no longer be available (I haven't run Windows since Windows98). I found this:
https://www.computerhope.com/issues/ch000549.htm
which purports to tell you how to set your "path". It might be better to go straight to MicroSoft In any case, get nasm.exe on your "path". Although you don't need it yet, you probably want to do the same with ndisasm.exe. Then you're ready for the fun part.

I almost hate to ask what you've got for an example file. For some reason, a lot of people find an example for Linux. The "int 80h" is a clue. "int 21h" won't work on modern Windows, either. Something with "MessageBoxA" in it is probably the easiest place to start. Come back if you have further questions.

Best,
Frank


Offline chris.

  • Jr. Member
  • *
  • Posts: 2
I got it to work, but now I am trying to run a simple hello world script.

On the very bottom of this guide in the section titled "Compiling and Linking an Assembly Program in NASM" (https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm

I can do everything up until "To link the object file and create an executable file named hello, type ld -m elf_i386 -s -o hello hello.o", after which I should expect a .exe file to appear in the folder. Correct?

When I do enter "ld -m elf_i386 -s -o hello hello.o" I get an error that states "ld: unrecognised emulation mode: elf_i386
Supported emulations: i386pe"

My take on this is that I cannot use "elf_i386" on Windows 10?

I am not sure, but am searching for similar issues hopping to find a solution.

If anyone knows could they explain please?


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2358
  • Country: us
Hi Chris,

You are correct, "elf" is a Linux format... and the program, with "int 0x80" in it is for Linux, too. That tutorial doesn't say it's for Linux, but it is. I can see now why people keep finding that code. When I search for "windows assembly tutorial" it is prominantly featured, looks good, and doesn't say it's not for Windows - the "int 80h" is the dead giveaway. It won't work on Windows. I didn't find any good tutorials for Windows assembly! The Iczelion tutorials are the classic... but they use Masm and depend heavily on Masm's built in macros. We can arrange to include such macros, but they hide the inner workings from beginners. I may have Nasm translations of Iczelion's code... somewhere(?).

We don't have a tutorial here, but there are some examples - starting around page 3 or 4 of the example code...

Here's an example of MessageBoxA:
https://forum.nasm.us/index.php?topic=1918.0

Here's one using "_printf" (64 bit):
https://forum.nasm.us/index.php?topic=1751.0

There are a number of excellent examples from "encryptor256", but they tend to be a little advanced for beginners.

If you start with the MessageBox code, and the ld command line from your first "guide", you might have some success. I don't know where MinGW puts the libraries, and you may need them (kernel32.lib, user32.lib, etc.). GoLink manages it without libraries, if you want to use that instead of ld. Using gcc - even if you have no C code to compile - has the advantage that gcc knows what to tell ld, if you want to try that.

Dr. Paul Carter's tutorial is good. He hides the interface with the OS behind the C library. This has the advantage that you can use it with any OS, but the disadvantage that it hides the details of interfacing with the OS, if that's what you were interested in... http:/www.drpaulcarter.com/pcasm

Good luck, Chris - I have a feeling you may need it!

Best,
Frank