Here is a 1.44 MB GUI Operating System written entirely in assembler code. This system can fit on a floppy disk.
Check it @ http://www.menuetos.net/
If you run it, you will find the system to be lightening fast(especially if you don't actually run it from a floppy disk :P)
So let's experiment with 80x86 Assembler(this program will work on anything). Though our code will work on any system, the program to build the code will not work on any system.
We are going to use my girlfriend's windows machine because so many people use Windows. She has Windows XP.
If you have a newer version of windows, you will have to download the appropriate software for your computer from this link:
I would get the SDK version.
You will be using ntsd or cdb instead of "debug" if you are not running good old XP.
Step 1: Open Up a Command Window
Type "cmd" and hit enter. "CMD" stands for ComManD window.
You should now get a nice black window(pic 2).
Step 2: The Debugger
If you're in windows XP, type "debug" inside of that black window and hit enter.
You should get a "tack" or a "minus sign" on the line below(pic 1). Here is where we will type our debug commands.
Let's type the debug command to begin writing assembler code.
type "a" and hit enter
Now we see a few hexadecimal numbers which represent the address in memory that we're writing code. We can write assembler code right here!
Step 3: Writing a Little Bit of Code
Let's go ahead and type "mov ah, 2"
This "mov"es a "2" into the upper(or "h"igher) half of the 16 bits of the "a" register
That "2" is going to tell the processor what command we want to run when we call the 21st interrupt request. The "2" command is the command to print a character to the screen.
So how do we know what character the processor is going to write to the screen?
That's contained in the "dl" register. Can you guess what the "dl" register is before going to the next page?
Step 4: Finishing the Code
Now let's set what character we want to display:
I want to display the smiley face(character 1)
For a list of characters and their corresponding numbers, you can look at the ASCII chart here:
type "mov dl, 1" and hit enter to set the character we intend to display
Now we have to tell the computer to actually run with our two parameters.
type "int 21" and hit enter.
Now let's run our code. It's going to type a smiley and then normally end.
Simply hit enter again and you'll be back to a minus sign. See pic 2
Type "g" next to the minus sign and hit enter.
You should see something like Picture 3.
Step 5: Adding Some Fun
"a 106" allows us to continue writing code where we left off.
"jmp 100" says to go to the beginning of the code(address "100") and continue running from there.
What do you think this new code will output to the screen when we run it?
Step 6: Woah!
Hold the "Ctrl" button and press "C" to stop it!
You can run it again by typing "g" and then enter.
You will notice that the computer is able to display the characters a lot faster if you go into full screen mode by holding down "Alt" and tapping "Enter"
Hold down "Alt" and tap "Enter" to get out of full screen mode.
That's it for this lesson. You've got your first glimpse into assembler. Check out other instructables that use Debug for a Hello World program.