Re: NASM HelloWorld - DOS
- From: Evenbit <nbaker2328@xxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 14:18:31 -0700
On Jul 30, 9:35 pm, "Jim Carlock" <anonym...@xxxxxxxxx> wrote:
Are there any other things that might be a little more interesting that
can be added and/or changed in any way without getting too much
more complicated?
<code>
;
; Hello world! example.
; Subsystem: DOS
;
; COMPILE_1: nasmw.exe -fbin -ohellow.com hello.asm
; COMPILE_2: nasmw.exe -fbin -ohellow.exe hello.asm
; LINK_1: NOT REQUIRED FOR .com or DOS .exe
; LINK_2:
;
Just because you give the file an "exe" extension does not
automatically make it into a standard DOS executable. Since it
doesn't contain the proper header, the OS loader will assume it to be
a typical "com" program and treat it as such.
If you go here:
http://sourceforge.net/project/showfiles.php?group_id=6208
....scroll down to the "DOS 16-bit binaries (OBSOLETE)" heading and get
the 0.98.38 archive (the newer 0.98.39 lacks this for some reason)
which contains a "misc" directory with a few useful include files that
define macros and such. The "exebin.mac" provides the needed header
to create a proper DOS "*.exe" program using NASM. It is reprinted
below:
; -*- nasm -*-
; NASM macro file to allow the `bin' output format to generate
; simple .EXE files by constructing the EXE header by hand.
; Adapted from a contribution by Yann Guidon <whygee_corp@xxxxxx>
%define EXE_stack_size EXE_realstacksize
%macro EXE_begin 0
ORG 0E0h
section .text
header_start:
db 4Dh,5Ah ; EXE file signature
dw EXE_allocsize % 512
dw (EXE_allocsize + 511) / 512
dw 0 ; relocation information: none
dw (header_end-header_start)/16 ; header size in paragraphs
dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem
dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem
dw -10h ; Initial SS (before fixup)
dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK)
dw 0 ; (no) Checksum
dw 100h ; Initial IP - start just after the header
dw -10h ; Initial CS (before fixup)
dw 0 ; file offset to relocation table: none
dw 0 ; (no overlay)
align 16,db 0
header_end:
EXE_startcode:
section .data
EXE_startdata:
section .bss
EXE_startbss:
%endmacro
%macro EXE_stack 1
EXE_realstacksize equ %1
%define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end
%endmacro
%macro EXE_end 0
section .text
EXE_endcode:
section .data
EXE_enddata:
section .bss
alignb 4
EXE_endbss:
EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3)
EXE_datasize equ EXE_enddata-EXE_startdata
EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3)
EXE_allocsize equ EXE_acodesize + EXE_datasize
EXE_stack_size equ 0x800 ; default if nothing else was used
%endmacro
As far as I can tell, the GNU LESSER GENERAL PUBLIC LICENSE Version
2.1 applies to the above code snippet.
Nathan.
.
- References:
- NASM HelloWorld - DOS
- From: Jim Carlock
- NASM HelloWorld - DOS
- Prev by Date: Re: Definitions - What are yours?
- Previous by thread: Re: NASM HelloWorld - DOS
- Next by thread: Re: misc, OT: C compiler, x86-64 or not x86-64...
- Index(es):
Relevant Pages
|