how to create EXEs with NASM...

Started by
23 comments, last by Crypter 16 years, 11 months ago
...Anyone know how? I use this to get a COM file: "nasmw -f bin whatever.asm -o whatever.com" (I don't know why it came as 'nasmw.exe' and not 'nasm.exe.' I could always change it to 'nasm.exe' if I wanted) ...So, how do I create an EXE out of the COM file? Or, if I can, how do I create an EXE using "-f" in the nasmw command line? (Or any other way to make an EXE with NASM code) Thanks. :)
Advertisement
It is platform specfic, but assuming Windows:

nasmw input.asm -f win32 -o output.exe

If you do nasmw -h to print the help, it gives instructions on how to obtain a list of the valid format arguments which may be used.

You could create an EXE directly from the COM file, but it'd require manually writing the PE header -- which would be a reasonably pointless exercise.
[TheUnbeliever]
But how do I create a standalone EXE, not running on top of any other OS? An OS itself, basically.
Quote:Original post by andrew1123
But how do I create a standalone EXE, not running on top of any other OS? An OS itself, basically.


That's an answer which could fill a book (literally) and so I will simply direct you to OSDev.org - it hosts wikis (one of which was moved from Mega-Tokyo) which detail a number of things -- including the setup of a cross compiler toolchain -- involved in the development process. It's not too hard, although it's not quite absolutely trivial.

Sorry I can't give a better response -- but even the process of setting up the development environment is quite a lengthy description, never mind the design decisions in creating an operating system (or even, to an extent, any freestanding program) itself.
[TheUnbeliever]
wait a minute, i think you can just save the bin format as EXE. it works.
I second OSDev.org

OSs are not a single *.exe. An OS is just an envirement made up of many programs, ranging from pure binary, to ELF,EXE, etc file formats.

For example, the bootloader will be a pure binary program, which will load
and execute either a second stage loader, or a main kernel program. This
program could be ELF, or even an EXE.

btw, using a cross compilier is not required (Its recommended, although
I could never get it to work). I use DJGPP/NASM/binutils/LD-elf instead ;)

There is alot involved, as previously posted. Good luck!
Quote:Original post by Crypter
I second OSDev.org

OSs are not a single *.exe. An OS is just an envirement made up of many programs, ranging from pure binary, to ELF,EXE, etc file formats.

For example, the bootloader will be a pure binary program, which will load
and execute either a second stage loader, or a main kernel program. This
program could be ELF, or even an EXE.

btw, using a cross compilier is not required (Its recommended, although
I could never get it to work). I use DJGPP/NASM/binutils/LD-elf instead ;)

There is alot involved, as previously posted. Good luck!


All I meant by OS is that it doesn't run on top of another OS. So, saving it as binary, that's standalone, right? It doesn't NEED MS-DOS, right? Any x86 PC, right?
Every program you write and use runs on top of the OS. Any file on your computer with an .exe extension is likely in portable executable format and is interpreted by and run by the windows operating system.

The bin output option for nasm just dumps the straight binary bits of the machine code to a file, rather than provided them with any particular header like elf or pe. It may be the case that windows can run such files - I think it interprets them as old ms-dos com files but I'm not sure.

In any case I'm not sure what you mean by an "exe" and not running on top of the OS. Any file with an .exe extension is almost certainly a windows executable and requires windows to run.

Actually running a program in the absence of an OS is very difficult and requires starting in 16-bit assembly. You have access to no system calls, no drivers, no memory management, etc.

You should be more specific about what you are trying to do
What I'm trying to do is write a program in NASM that doesn't need to run on top of say Windows. I didn't know that EXE was only in Windows. I thought it was the universal executable name. .COM is DOS executable, so can't that run without Windows? I'm not using any Window libraries, no drivers. here's an example of some NASM code

ORG 100h
MOV AH,09h
MOV DX,STRING
INT 21h
MOV AH,00h
INT 16h
STRING DB "Hello World!$"

That doesn't really NEED Windows, does it? Just the Processor (And maybe some other PC parts, too), right?
Quote:
All I meant by OS is that it doesn't run on top of another OS. So, saving it as binary, that's standalone, right? It doesn't NEED MS-DOS, right? Any x86 PC, right?

That is correct -- kind of. Your program will not boot from it unless
you have a bootloader program.

Also, depending on resources use (and its a 32bit program), you will need
to set up the GDT and IDT tables, and jump into a 32bit mode (Such as pmode)

If you dont want it to work with an OS, you will still need to develope
these small details. (All of these are useually handled by the bootloader)

Using your code, you would also need to insure you load your program at
address 0100:0. And you will need to write your own INT 21h and INT 16h
routines, as your code will not work.

I would like to add INT 21h are DOS interrupts. As you are not using DOS,
INT 21h will be completely non existant. Sorry :(

Also, EXE is just a file format (The most common are MZ and PE formats)
It isnt Windows-only.

This topic is closed to new replies.

Advertisement