NewBasic Compiler -- An x86 Compiler/Assembler/Disassembler for DOS
The NewBasic Compiler, NBC.EXE (found here), is a small C compiler which produces assembly code
ready to assemble with the NBASM assembler.
This compiler is heavily based on SmallerC.
The story:
I have been writing a small operating system called FYSOS for some time. As with operating systems, you have the first stage boot code, the loader (aka the second stage boot code), and the kernel.
The first stage boot code is written in assembly and usually assembles to a few 512-byte sectors. It is fairly difficult to write this stage in any other language other than assembly. The advantage is that you only have to write a minimum amount of code to load the second stage loader.
My second stage loader started out to be quite small and was written in assembly language. As my loader and OS advanced in function, the loader started to become quite large. After all, it now contains code to use at least five different file systems and BZ2 type compression.
After a while, the assembly files for this loader became quite large and difficult to keep track of, let alone modify.
Then Alex started working on the SmallerC compiler mentioned above and I had the thought that I could take his generous offering and modify it for my needs. After a bit of work, I was able to modify his compiler to output NBASM .asm code, along with a few other changes.
I was then able to start to write my loader code, the second stage boot code, in C. Once I started, I realized that with a flat address space, I needed some of the memory pointers to use a segment register other than the default of DS. Therefore, I started to find how to make the compiler produce these segment overrides.
I'll explain and give examples of these additions below, but first a few more notes. Alex has added much more capabilities to his SmallerC compiler than mine has. If mine compiles my loader code, then I don't have much more interest in making it better until the need arises. However, since I now know how to modify the compiler to output these segment overrides, I may take his latest code, which is much more C compliant than mine, and modify it again.
We shall see if the time and interest arises.
Examples of how the compiler is different than others:
- Example: The use of the farC, farD, farE, farF, and farG pointers. These allow you to specify a segment override in your assembly code.
- Example: Specifing 16-bit real mode, 32-bit real mode, and 32-bit protected mode code.
Please Note:
- Please note that this compiler was built for the sole purpose to compile my C loader file source code to NBASM assembly source code to make it much more managable to code. Use this compiler at your own risk. It may, and probably does produce a few bugs within your ASM code, and it does not, repeat, does not produce efficient code. Once you have a working C project, compiled to assembly, please work over your assembly code to verify there are no errors and to make it more efficient code.
- Also, please note that this compiler does not produce a working executable for DOS, Windows, or any other operating system. It produces exactly what is found in the C source code. In other words, it does not add any stubs, EXE headers, or other items to the file to make it executable. However, you can create DOS .com executable files with a few hand-written modifications to the produced .asm file(s).
- As stated before, when interest and time allows, I may work on this compiler further, especially taking the current workings of Alex's SmallerC and adding these advances to my compiler.
- I also want to make sure and thank Alex for the work he has done on SmallerC which in turn has allowed me to create this compiler. Thank you Alex...