Languages : 80x86 assembly language
Tools : DEBUG.EXE
Brief : A very very short introduction to assembly language programming using
DEBUG.EXE. So short that it walks you through creating a program, but
explains almost nothing along the way.
Welcome to assembly language programming! Assembly language (also known as assembler language) is only one step away from the language your computer speaks internally - so this is really getting into the nuts and bolts of things! We call this "low level" programming, 'cause at this level, it's a lot of hard work and you have to be aware of a huge amount more detail. Languages like QBasic are at a "higher level" than assembler, because they hide much of the detail of what's going on and how things work. Learning high level languages and never studying assembler is a little limiting because it can be hard to understand the higher level languages when you don't understand the technical behind-the-scenes stuff. So not only is assembly language programming a lot if fun, and not only do you get to do lots of cool things, some of which aren't possible in other languages, and not only do you learn your PC inside out when assembly language programming, but on top of it all, learning assembly language programming improves your understanding of all other programming languages, and thus makes you a better programmer.
Some of you will like it, some will take a little while to warm to it, others will fall in love with assembler instantly, but if you have little PCs floating around your veins (like they say I do) then you will find something irresistibly intriguing about low level programming. (And by the modern definition of the word, that would make you a nerd. Welcome to the club! :o) )
Your First Assembly Language Program
Our tool of choice : DOS DEBUG. To start it, first open up a command prompt (found on your start menu under "Programs - Accessories", and referred to as "MS DOS Prompt" or similar in some older versions of Windows (and perhaps under "Programs - Accessories - System Tools" in some older versions of Windows - I don't recall for sure)).
WARNING! Some older versions of Windows start the MS DOS Prompt in "full screen" mode. You will almost certainly want to use Alt + Enter to change it back from "full screen" mode to "windowed" mode. Alt + Enter is the magic key combination.
Don't panic if your screen doesn't look exactly like this. Different versions of Windows do things a little differently.
In the command prompt, type "debug" and press Enter. (For Windows 98 users, you will probably first need to type a line such as "CD C:\Windows\Command".) Up comes a new line with nothing but a little minus sign. This minus sign is called the Debug Prompt.
If instead of this, you get a message saying something like "Bad command or filename", then you're probably running an older version of Windows and need to change the current directory to the directory that houses DEBUG.EXE. Email the group for instructions if you need assistance.
Now, very carefully, type in the following, pressing Enter at the end of each line of text. I realise you don't (yet) have a clue what the following does, but you'll find out soon enough...
a 100
mov ah,9
mov dx,200
int 21
mov ah,0
int 16
mov ah,0
int 21
Typing in our first assembly language program.
You'll notice that after the first line, you didn't get the Debug prompt, but instead got some funny numbers. They all have significant meaning, but for now, just press Enter again and you'll get back to the standard Debug prompt.
Back at the Debug prompt.
Now you need to type a few more things, taking my word for it again that it'll do something useful.
f 200 l100 "Hello! This is my first assembly language program!$"
n First.com
r cx
200
w
Now, what actually have you done? Let's find out! Type "quit" (without the quote marks) and press Enter, and you're back at the command prompt. Then type "First" and press Enter. What do you see? If all has gone well, you should see your wonderful greeting. And the program will wait for you to press a key before it ends.
Quick Overview Of The Parts Of The Program
The first three lines of the assembly language code ("mov ah,9 / mov dx,200 / int 21") are responsible for displaying the message. The next two lines ("mov ah,0 / int 16") are responsible for waiting for a keypress. And the final two lines ("mov ah,0 / int 21") exit the program. You can play around a bit by, for example, having the "mov ah,0 / int 16" twice, or perhaps putting it before the "mov ah,9 / mov dx,200 / int 21" bit. Also, as I'm sure you've guessed, you can change the message very easily, and I'm sure you've guessed how.
Did you notice that the "$" sign at the end of the message did not display? What happens if you try to include a dollar sign in the message? Aha! So what does the dollar sign do?
And unfortunately I have to get moving and leave it there for the day, but you can proudly send this program to your friends - "My first assembly language program!", and they can run it and say "Is that all it does?". :o) Ah - non-nerds just don't understand the joys of nerdhood... :o)