;LOADEXE.ASM
;Easy Way to get Any OS to Load a .EXE File
;By Shawn T. Cook
;Version 1.0
;simply reads the .EXE to 8000:0 using int 21h
;then does some stuff and runs the .EXE
;Shows a 'E' if not a MZ header...
;change filename.exe to the name of your .EXE file!
Org 0x0100
RunEXE:
push cs
push cs
pop ds
pop es
mov ah, 0x3d
mov al, 0
mov dx, ExeName
int 21h
mov bx, ax
mov ax, 0x8000
mov ds, ax
mov dx, 0
KeepLoading:
mov cx, 0x10
mov ah, 0x3f ;read
int 21h
jc NotKeepLoading
cmp ax, 0
je NotKeepLoading
mov ax, ds
add ax, 1
mov ds, ax
jmp KeepLoading
NotKeepLoading:
mov ah, 0x3e ;close
int 21h
ReadEXEFile:
mov ax, 0x8000
mov ds, ax
cmp word [ds:0], 5A4Dh ; "MZ" signature?
jne NotEXE
RelocateEXE:
add ax, [ds:08h] ; ax = image base
mov cx, [ds:06h] ; cx = reloc items
mov bx, [ds:18h] ; bx = reloc table pointer
jcxz RelocationDone
ReloCycle:
mov di, [bx] ; di = item ofs
mov dx, [bx+2] ; dx = item seg (rel)
add dx, ax ; dx = item seg (abs)
push ds
mov ds, dx ; ds = dx
add [di], ax ; fixup
pop ds
add bx, 4 ; point to next entry
loop ReloCycle
RelocationDone:
mov bx, ax
add bx, [ds:0Eh]
mov ss, bx ; ss for EXE
mov sp, [ds:10h] ; sp for EXE
add ax, [ds:16h] ; cs
push ax
push word [ds:14h] ; ip
Run:
; set the magic number so the program knows who has loaded it:
mov si, 16381 ; prime number 2**14-3
mov di, 32749 ; prime number 2**15-19
mov bp, 65521 ; prime number 2**16-15
retf
NotEXE:
mov ah, 0x0e
mov al, 'E'
int 0x10
ret
ExeName db 'filename.exe',0