NASM 0.98p3.5
[nasm.git] / exebin.mac
blob89c688988cd0109b5259b11ea5dd0296c3fbfa5e
1 ; -*- nasm -*-
3 ; NASM macro file to allow the `bin' output format to generate
5 ; simple .EXE files by constructing the EXE header by hand.
7 ; Adapted from a contribution by Yann Guidon <whygee_corp@hol.fr>
11 %define EXE_stack_size EXE_realstacksize
15 %macro EXE_begin 0
17           ORG 0E0h
19           section .text
23 header_start:
25           db 4Dh,5Ah            ; EXE file signature
27           dw EXE_allocsize % 512
29           dw (EXE_allocsize + 511) / 512
31           dw 0                  ; relocation information: none
33           dw (header_end-header_start)/16 ; header size in paragraphs
35           dw (EXE_absssize + EXE_realstacksize) / 16 ; min extra mem
37           dw (EXE_absssize + EXE_realstacksize) / 16 ; max extra mem
39           dw -10h               ; Initial SS (before fixup)
41           dw EXE_endbss + EXE_realstacksize ; Initial SP (1K DPMI+1K STACK)
43           dw 0                  ; (no) Checksum
45           dw 100h               ; Initial IP - start just after the header
47           dw -10h               ; Initial CS (before fixup)
49           dw 0                  ; file offset to relocation table: none
51           dw 0                  ; (no overlay)
53           align 16,db 0
55 header_end:
59 EXE_startcode:
61           section .data
63 EXE_startdata:
65           section .bss
67 EXE_startbss:
69 %endmacro
73 %macro EXE_stack 1
75 EXE_realstacksize equ %1
77 %define EXE_stack_size EXE_bogusstacksize ; defeat EQU in EXE_end
79 %endmacro
83 %macro EXE_end 0
85           section .text
87 EXE_endcode:
89           section .data
91 EXE_enddata:
93           section .bss
95           alignb 4
97 EXE_endbss:
101 EXE_acodesize equ (EXE_endcode-EXE_startcode+3) & (~3)
103 EXE_datasize equ EXE_enddata-EXE_startdata
105 EXE_absssize equ (EXE_endbss-EXE_startbss+3) & (~3)
107 EXE_allocsize equ EXE_acodesize + EXE_datasize
111 EXE_stack_size equ 0x800        ; default if nothing else was used
113 %endmacro