Author Topic: Using nasm-2.10.07-win32 in Windws 7  (Read 13558 times)

Offline S Mahen

  • Jr. Member
  • *
  • Posts: 21
Using nasm-2.10.07-win32 in Windws 7
« on: July 03, 2013, 08:31:52 AM »
I am new to forum. I installed nasm-2.10.07-win32 in Windws 7. I was trying to write Hello world program (32 bit). I am not able use nasm in windows.

I'm used: nasm -f elf32 hw32.asm -o hw32.exe
Then I executed hw32.exe but it is giving me "This version of C:\nasm\hw32.exe is not compatible with the version of Windows" error.

Please help me in assembling using nasm.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Using nasm-2.10.07-win32 in Windws 7
« Reply #1 on: July 03, 2013, 10:07:53 AM »
The first thing to know about Nasm is that it will do a lot of different things - controlled mostly by command line switches. One of the most important ones is the "-f" switch. This selects which output format Nasm will emit. You want to select an output format suitable for your OS. "-f elf32" is a linkable object file for Linux (and BSD). For Windows, you'd want "-f win32" (or possibly "-f win64").

A less important (generally) command line switch  is "-o". This controls (only!) the name of the output file.    You've named your file "hw32.exe", but it's still a linkable object file for Linux. The default output name for "-f win32", if you don't use the "-o" switch, would be "hw32.obj". This should be fine, but you'll have to run it through a linker to get an executable out of it. Simply naming it "hw32.exe" with the "-o" switch isn't going to work, either. I think the most commonly used linker for Nasm/Windows is Jeremy Gordon's "golink", but other linkers will work.

I would suggest that the easiest way to get started is to download the NASMX package and try the examples:
http://sourceforge.net/projects/nasmx/files/nasmx-1.2/windows/

This will include Nasm (possibly not the latest version), Golink, and some useful include files, as well as examples.

You don't show the source code you're trying to assemble. If it has "int 80h" in it, it's for Linux and isn't going to work on Windows even it it assembles and links without eroor. Like the selected output format, the source code has to be suitable for your OS. They vary wildly!

Nasm has a nice manual. If you didn't download it, it can be downloaded or accessed online here:
http://www.nasm.us/docs.php

You won't want to read the whole thing, but the parts that cover Nasm usage in general, and the parts that cover your OS might help you get started with more success.

Feel free to ask more questions (if any). :)

Best,
Frank


Offline S Mahen

  • Jr. Member
  • *
  • Posts: 21
Re: Using nasm-2.10.07-win32 in Windws 7
« Reply #2 on: July 08, 2013, 06:14:47 AM »
Thank you for your reply.

I'm using int 80h in my code to display hello world message, Which you mentioned is for linux.

Now, I installed fedora 17 and downloaded nasm from http://www.nasm.us/pub/nasm/releasebuilds/2.10.07/nasm-2.10.07.tar.gz

I am really finding it difficult to install it and use it.

Please help me.




Offline avcaballero

  • Full Member
  • **
  • Posts: 133
  • Country: es
    • Abre los Ojos al Ensamblador
Re: Using nasm-2.10.07-win32 in Windws 7
« Reply #3 on: July 08, 2013, 06:45:14 AM »
Hello, these ones for DOS, (also inside Win):

1) COM example. Here it is an example of a com "Hello world" in nasm sintax
http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap02.html#SNasmCOM

2) EXE example. This one for exe:
http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap02.html#SNasmEXE

3) And here it is the summary for compile it (COM and EXE, you choose):
http://www.abreojosensamblador.net/Productos/AOE/html/Pags_en/Chap02.html#Summary

I recommend you to start with COM format, because, it is easier and don't need linker with NASM.

Regards.

PD. Notice that, if you are working in a 64bit system, you will be able to compile it, but, you won't execute it, because they are 16 bits, that are not supported by the new W7 64 bits, you maybe need for it the dosbox tool ;)
« Last Edit: July 08, 2013, 06:57:29 AM by avcaballero »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Using nasm-2.10.07-win32 in Windws 7
« Reply #4 on: July 08, 2013, 01:53:11 PM »
Heh. We have drifted far from the original topic! Perhaps this should be a new question. Well... onward...

I should point out that my system is extremely obsolete. Things have changed, and my advice may be too outdated to be useful. Well... onward...

There are basic Unix installation instructions in the manuaL

http://www.nasm.us/xdoc/2.10.07/html/nasmdoc1.html#section-1.3.2

That may be enough to get you going. I do it slightly differently. I work entirely in my home directory. This is not ideal - makes for a very cluttered home directory after a while - but it works for me. I've downloaded my .tar.gz file there, and I unpack it there - "tar zxf nasm-10.7.tar gz". (hint: you can type in just part of this and hit TAB to complete it) Assuming this goes well, "cd nasm-10.7", the top directory of the source code. Then type "./configure". This should produce a suitable Makefile. Then I type "make everything". I'm not sure the "everything" and "install_everything" targets are mentioned in the manual - they make documentation in several formats and some "rdoff" utilities (a homemade Nasm linkable format), as well as nasm and ndisasm. You probably don't need/want this, but that's the way I do it. Then I switch to root (type "su" and provide the root password) and do "make install_everything". I'm done - type "exit" (or "logout") to quit being root, and "cd" back to the directory where my source code for "hw32" and all lives.

The only reason I do "make" and "make install" as two separate steps is so I'll "own" the Nasm source files and can edit them without root permission. You probably don't need to do this. Once you've gotten by "./configure", just (as root) "make install" should do everything you need in one step. Some systems don't seem to have a separate "root" account and do everything with "sudo". In that case "sudo make install" should do everything in one step.

Now you can go back to "nasm -f elf32 hw32.asm". This should produce "hw32.o" (you can name it something else, but shouldn't need to). On a 32-bit system, you can link it with "ld -o hw32 hw32.o" - almost a palindrome :) For a 64-bit system (which I presume Fedora 17 is) ld will be expecting to link a 64-bit file, and will need "ld -o hw32 hw32.o -melf_i386" to tell it we want a 32-bit file. At this point, typing "hw32" should get you "hello world" on the screen. Whew!

If you don't get to the end, try to remember exactly what you did, and the exact error message (or whatever happened), and we'll try to help you out.

Best,
Frank


Offline avcaballero

  • Full Member
  • **
  • Posts: 133
  • Country: es
    • Abre los Ojos al Ensamblador
Re: Using nasm-2.10.07-win32 in Windws 7
« Reply #5 on: July 09, 2013, 06:20:21 AM »
Ops, sorry, I didn't notice "32 bits"  ;D. NasmX would be a good choice  8)