d a v i d j w a l l i n g . c o m

Custom Operating System Series

Part Seven : Handling Console Commands

This article is part seven in a series introducing system software concepts for Intel® x86 or compatible processors in protected mode. In this series we are developing a simple protected mode operating system in assembly language. We are using the Netwide Assembler (NASM) to assemble our code and VMware® Player as our test platform.

In our first six articles, we configured VMware Player to launch a virtual machine that loaded a boot sector from a floppy disk image file, called our boot sector code which searched the disk image file for an operating system program, loaded that program into memory and called it, which configured a 32-bit operating system kernel, entered protected mode and transfered control to a task, capturing keyboard input and reporting keystroke data to an operator information area as well as echoing user input to the console screen.

In this article, we will extend our console task to interpret commands entered at the keyboard and respond to known commands. Three commands are supported in this article's code, "clear", "exit" and "ver". The "clear" command clears the console screen and returns the cursor to the top of the screen after the input prompt. The "exit" command resets the virtual machine. The "ver" command displays the version of the operating system.

1. Additional Equates

In this article we add additional ASCII equates for parentheses, numeric range tests and the equal sign.

2. New Service Requests

Next, We add new service request table entries, functions and macros. This article introduces serveral string-handling functions, LeftTrimString, RightTrimString, GetStringLength, UpperCaseString and CompareStrings. Also, we introduce a ResetSystem service to restart the virtual machine in response to an "exit" command. The GetStringLength is not yet used as a service routine of its own, but is called by other string-handling service routines.

3. New Kernel Functions

The new functions added are LeftTrimString, RightTrimString, GetStringLength, UpperCaseString, CompareStrings and ResetSystem

4. Console Task Updates

We update our console task main thread to pass our input buffer to a new routine, ConParseCommand. If the command is not found, the unknown-command message is displayed. Otherwise, the valid command number is convered into an index into a jump table to a routine that handles the command.

The ConParseCommand routine trims the command entered by the user and converts lower-case to upper-case. Then, the compareStrings macro invokes the kernel string-compare service to check if the command is found on a table of known commands.

The concmdjmp table points to three new functions that handle known commands, "conclear", "conexit" and "conver". These routines, in turn, invoke each of our new service requests. With these additions, the operating system can now respond to known commands.


In this article we have added logic to interpret console input and handle known commands. In our next article, we will add support for additional date and time commands that interface with the real-time clock.

Program Notes

Here is a link to the entire listing of the code and data from this lab.

Program Listing

Revised 10 October 2014