Quick rundown on Machine Code - Assembly - C - C++ - Basic.
A CPU executes machine code; that's just '0' and '1', with certain sequences making sense to the CPU.
Assembly is a way of making machine code comprehensible for humans. Instead of giving 100101 for "move a long word", 110 for "from register EAX", 010 for "to memory", and a 32-bit binary sequence for the memory address, you say
(No, the binary encoding is not correct. I'm too lazy to look it up.)
The
Assembler will take the above code, and
assemble it to machine code.
One example of
functional Assembler:
Code: Select all
mov $start, %ebx
jmp 2f
1: call *(%ebx)
add $4, %ebx
2: cmp $end, %ebx
jb 1b
This takes an array of function pointers starting at $start and ending at $end, and executes each function pointed at.
Now this is still pretty arcane. C, on the other hand, is a "high-level language" (HLL) where you no longer try to understand the CPU, but make the CPU understand you. Above code would look like this in C:
Code: Select all
typedef func* (*void)();
for (func = START; func != END; ++func)
{
func();
}
Granted, that's still not beautiful (not even for C code), but it's already much "clearer" than Assembly. You feed this code to a
compiler, and it will
compile this into machine code that will be only marginally less effective than hand-optimized Assembly (if you're an Assembler professional), probably even
more effective (if you're an average Assembly programmer). While there are some parts of an OS that have to be done in Assembly for technical reasons, C has been the OS-implementing language of choice for decades.
C++, now, is a
superset of C that does introduce much "syntactic suggar": Stuff that makes large-scale programming, object-oriented programming, and generic programming much easier. This cannot be easily displayed in a short code example. If you aren't a hard-core C++ coder to begin with, forget about using it for OS development, since it's a much more complex language than C. (Although the claim that it is
per se inferor to C is false - I'd say it's on par, depending on what you're looking for.)
Basic, now, is a completely different ballgame. Assembly, C, or C++ are translated into
machine code, and the translators (assembler / compiler) can be instructed to generate machine code that does not assume the existence of an operating system.
But many Basic dialects are
interpreted languages. That means that the Basic code is translated into machine code
at runtime, which requires the presence of an
interpreter in the system. Even
if you happen to have a Basic
compiler at hand that directly translates Basic into machine code, that would still be machine code that assumes the presence of an OS for delegating such tasks as opening a file or printing a text to screen.
Basic was simply not designed for system programming. It is likely to have poorer performance and larger memory requirements. It is poorly standarized (is it at all?), so what works on one Basic interpreter breaks on another. No OS I know of has ever been written in Basic, so chances are slim that you'd find someone who can help you with OS-level Basic code.
Bottom line: You
will need several dozen / hundred lines of Assembly. Whether you use Assembly, C, C++, or Something Completely Different (tm) for the rest is up to you, mainly depending on your experience with the languages. The most common choice is C, since Assembly is considered too low-level, and C++ too new / complex / little known.
Whenever you go for Something Completely Different (tm), be aware that you will be out in uncharted waters with little to help you tutorial / literature / forum wise. Stay away from languages who have not been designed for this kind of work, which includes Basic, Pascal, Cobol, AP/L and Intercal.