;; Cross platform executable, 07/2005 ;; Milani Giacomo ;; ;; $ nasm -felf crossplatexe.asm -o test.o ;; $ ld test.o -o testcpe.com ;; ;; (warning on entry point), now find _start symbol ;; end relink it, like elf entry (example:) ;; ;; $ nm test3.com | grep _start ;; 080490c8 A __bss_start ;; 0804809b t _start ;; ;; $ ld test.o -o test3.com -e 0x0804809b ;; ;; Now test it: ;; ;; (Linux:) ;; $ ./test3.com ;; Hello, World! ;; $ ;; ;; (DosEmu:) ;; C:\BIN>test3 ;; Hello, World! ;; C:\BIN> ;; ;; ;; How works: ;; Output file is ELF/COM executable, ;; It works like elf on *nix, and like .com on windows ;; Elf hdr makes on dos nothing important (only you must ;; be careful that assembled entry point address make's nothing ;; distruptable). If you have problem with entry point, you can ;; add extra nop on start of file. ;; Check the executable with debug.exe ;) ;; ;; The address of "hello world!" was computed by ld on ELF ;; (ld fix relocation). ;; On COM is absolute: ;; add edx,0100h (COM is mapped at address 100h, cause PSP) ;; add edx,00b8h (b8 is offset of string in file) ;; nop nop nop nop dos: xor dx,dx add edx,0100h add edx,00b8h mov ah,9 int 21h mov ah,4Ch int 21h _start: mov ecx,$msg mov eax,4 mov ebx,1 mov edx,15 int 80h mov eax,1 int 80h msg: db 'Hello, World!',0Dh,0Ah,'$'