Home > OS >  Is it possible to call an .EXE file from an .ASM code to run without an OS?
Is it possible to call an .EXE file from an .ASM code to run without an OS?

Time:05-30

So here I have an .EXE file that runs in full-screen, and I need to call it from .ASM language. To make it more clear, I am trying to make an OS prototype (idk if it makes me sound mad), where I have an .EXE file that I need to call from an .ASM code. I am a learner, so I am not sure if this is possible, but according to other answers on the net, I would have to make a basic I/O subsystem, memory management, and stuff (which an OS typically does). I would like to have an example where an .EXE while is called from .ASM code, and the .EXE is executed.

Thank You!, even if you only read this :)

And if you need the .EXE file with its components, I can provide you that, if you can help me...

CodePudding user response:

Most .EXE files use operating system services and won't work if these services are not provided. More specific: A DOS .EXE files requires the DOS APIs, e.g. INT 21h to be present. The most prominent operating system service used by application programs is the file system driver. The code in the .EXE file asks the operating system to open a file called DATA.BIN, and it's up to the operating system to locate the file on the disk. You can not run a .EXE file that tries to access files without any kind of operating system.

If you are writing your own operating system, you either have to implement a way to load a DOS kernel (e.g. MS-DOS, FreeDOS) from your operating system so the .EXE file can access the system services it requires, or your operating system needs to implement DOS-compatible services. Loading and executing an .EXE file is a straight-forward task (assuming you already have file access working). You load the header first. The header indicates the start of the executable code/data inside the EXE file and the size of it. You have to load that area, and finally you need to load the relocations (size and length of the relocation table is also included in the EXE header), and apply the relocations before setting the stack to the address requested in the EXE header and jumping to the entry point.

If you loaded a DOS kernel into your operating system, the DOS kernel already implements loading and executing EXE files, so you could just delegate the process of loading/starting to the DOS kernel by calling int 21h/AX=4B00h.

  • Related