Page 1 of 1

Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 7:10 am
by boygiandi
How to build an com or exe file ( bootloader will read it ) using nasm under linux ( ubuntu ) ?

Thanks

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 7:15 am
by Solar
[stupid post deleted.]

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 7:53 am
by stranger
nasm source_file -o file.com since bin is default output format.

Code: Select all

valid output formats for -f are (`*' denotes default):
  * bin       flat-form binary files (e.g. DOS .COM, .SYS)
    ith       Intel hex
    srec      Motorola S-records
    aout      Linux a.out object files
    aoutb     NetBSD/FreeBSD a.out object files
    coff      COFF (i386) object files (e.g. DJGPP for DOS)
    elf32     ELF32 (i386) object files (e.g. Linux)
    elf       ELF (short name for ELF32) 
    elf64     ELF64 (x86_64) object files (e.g. Linux)
    as86      Linux as86 (bin86 version 0.3) object files
    obj       MS-DOS 16-bit/32-bit OMF object files
    win32     Microsoft Win32 (i386) object files
    win64     Microsoft Win64 (x86-64) object files
    rdf       Relocatable Dynamic Object File Format v2.0
    ieee      IEEE-695 (LADsoft variant) object file format
    macho32   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files
    macho     MACHO (short name for MACHO32)
    macho64   NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files
    dbg       Trace of all info passed to output stage

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 8:43 am
by Chandra
stranger wrote:nasm source_file -o file.com since bin is default output format.
Hmm... Looks 'Broken'. This will generate default executable file for the OS (aout under Linux and exe under Windows). In any case, COM file cannot be forced as output by simply adding the '.com' extension.
[Side note: bin is not the default output format. Use -f bin to output flat binary]

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 8:52 am
by stranger
All I can say is that on gentoo NASM version 2.08.02 behaves as I described.
@sidenote, please note "(`*' denotes default):" and " * bin flat-form binary files (e.g. DOS .COM, .SYS)" lines

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 9:24 am
by Chandra
stranger wrote:All I can say is that on gentoo NASM version 2.08.02 behaves as I described.
@sidenote, please note "(`*' denotes default):" and " * bin flat-form binary files (e.g. DOS .COM, .SYS)" lines
Do you mean you get a 'COM' file under NASM as a default output format?

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 10:32 am
by Brendan
Hi,
Chandra wrote:
stranger wrote:All I can say is that on gentoo NASM version 2.08.02 behaves as I described.
@sidenote, please note "(`*' denotes default):" and " * bin flat-form binary files (e.g. DOS .COM, .SYS)" lines
Do you mean you get a 'COM' file under NASM as a default output format?
The default for NASM is (usually) to generate a flat binary (and it assumes 16-bit instructions). A DOS 'COM' file is nothing more than a flat binary, with 16-bit (real mode) instructions. The only thing you need to do is slap "org 0x0100" at the start of your source file.


Cheers,

Brendan

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 6:56 pm
by Tosi
And if you want to make a PE file, just compile a binutils that can take win32 or coff object files and output PE files. Then use nasm -f win32 file.asm and link the generated object file.

Re: Please help me to build an exe or com file under linux

Posted: Thu Mar 03, 2011 9:11 pm
by Chandra
Brendan wrote:Hi,
Chandra wrote:
stranger wrote:All I can say is that on gentoo NASM version 2.08.02 behaves as I described.
@sidenote, please note "(`*' denotes default):" and " * bin flat-form binary files (e.g. DOS .COM, .SYS)" lines
Do you mean you get a 'COM' file under NASM as a default output format?
The default for NASM is (usually) to generate a flat binary (and it assumes 16-bit instructions). A DOS 'COM' file is nothing more than a flat binary, with 16-bit (real mode) instructions. The only thing you need to do is slap "org 0x0100" at the start of your source file.


Cheers,

Brendan
Infact you're right. But again, COM files come with limitations. There are some hard facts that separates COM files from 'flat binary' files. COM files are meant to be run under 'Real Mode' and are always executed at a fixed location. Moreover, they are extremely limited in size, more specifically less than 64kb. This is not always the case with 'flat binary' files.
Hence, a simple assumption of OP's environment cannot be made because he is bound to be under such limitations if he wants to target a COM file.

The main point here, is that there's more to do with the code itself rather than the switch .

Re: Please help me to build an exe or com file under linux

Posted: Fri Mar 04, 2011 6:40 am
by stranger
Chandra wrote: The main point here, is that there's more to do with the code itself rather than the switch .
Of course, but the fact that OP asked specific question (NASM under Ubuntu), is IMHO good justification for assumption that he was interested in specific answer, not general rules for writing com files.