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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
boygiandi
Posts: 2
Joined: Mon Feb 21, 2011 5:29 am

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

Post by boygiandi »

How to build an com or exe file ( bootloader will read it ) using nasm under linux ( ubuntu ) ?

Thanks
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

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

Post by Solar »

[stupid post deleted.]
Last edited by Solar on Thu Mar 03, 2011 8:59 am, edited 1 time in total.
Every good solution is obvious once you've found it.
stranger
Posts: 17
Joined: Thu Mar 03, 2011 4:05 am

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

Post 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
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

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

Post 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]
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
stranger
Posts: 17
Joined: Thu Mar 03, 2011 4:05 am

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

Post 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
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

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

Post 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?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

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

Post 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.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

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

Post 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 .
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
stranger
Posts: 17
Joined: Thu Mar 03, 2011 4:05 am

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

Post 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.
Post Reply