Site hosted by Build your free website today!
Programming in Assembly

So you want to learn assembly language? Well, there's no doubt that it's one of the hardest languages to learn, but it's definately worth learning. It's a low-level language and is really more or less on the brink of machine code. Although you'll have to do a lot of typing, you'll appreciate the speed of your programs. I'll try and make assembly as easy to understand as possible, but if you think that I need to address a specific section more, go ahead and e-mail me. Of course, it is recommended that you have a assembler to type your code into, but if you don't that's okay. I learned most programming languages just by reading, but no matter how much you read, if you have something to experiment with, well then that can make up for hundreds of pages of a yawn-fest book.

First off, I think we should start with registers. Registers are just like keywords or library functions that many compilers such as C and QBASIC use. These predefined keywords help your program function. Some of the most common are the AX, BX, CX, and DX (which are all 16 bit). I don't want to stress too much on 32 bit registers because we're going to mainly be talking about the assembly on a 8086 processor. These four are the ones that have the responsibility of holding data. AX is the accumulator. AH and AL are the accumulator high and low values of bytes, thus the H and L. AX and it's counterparts are used in input and output situations most usually.

But before we expand into any more notes on assembly, I should formally begin this tutorial by talking about some hardware associations. First of all, what is all this talk about registers and blah, blah, blah? Come on Jeannie, you're just filling my brain up with info that I still don't know the meaning behind. Okay then, so let me try and get more in depth. Think of it this way - every tiny corner inside of the microprocessor that can hold a number is a register. So assembly is very much intertwined with hardware.

BX is the base. Like AX, it has BH and BL subparts.

CX is the counter. When you do loops in assembly (explained later on) it is CX that is used. It also has CH and CL.

DX is the displacement and has DH and DL. If you haven't noticed yet, all the registers so far have had and high and low byte values accompanied with them.

Along with registers, there are also segment registers and index registers. These will be covered shortly. Let's see if we can manage to do a small example of what we've learned. Of course, don't expect this example to be anything much because you've only learned of four registers so far.

MOV AX 1h So what did that mean? Well, the MOV meant move and the AX was one of the registers. AX is incredibly important because it can handle a lot of mathematical information. So that above example meant to move a value of 1h to the AX register. Why h attached to a 1? Well I just chose 1, but the h stood for hexidecimal and AX can handle 0 to FFFFh. If you've ever used HTML, the idea of hexadecimal values may seem familiar to you. Assembly uses hexadecimal values, but they are not mirrored off like versions of the HTML values. The only thing they share is the concept.

ADD AX 8h That has added 8H to the AX register causing there to be a total of 9h in the AX register. You can also use SUB for subtract such as: SUB AX 4h DEC and INC are also very handy. DEC will decrement the number in the register as in taking one away. So if there's only 4h in AX and you used: DEC AX that would leave the AX register left to hold 3h. INC increments such as add one. For these you do not have to express a value, just the register location.

Before I move on, it's important for me to introduce the register segments. The most commonly used ones are ES for extra segment, DS for data segment, SS for stack segment, and CS for code segment. Segments will usually be paired up with index registers broken off by a colon. For example ES:DI. The index's are DI for destination index and SI for source index. BP and SP are usually associated with pointers and are matched up against stack segments. Don't flip out on me yet, I'm trying to open up some basic points so that when I put it all together it won't seem so cryptic. Segments are presented with two numbers. Try this: go into your MS DOS prompt and type in debug. Now type in d and you'll be presented with two numbers like this: 1577: 0100. Actually, you should get a list of numbers. The first number (ex - 1577) is the segment number. The second number after the colon is the offset within the segment.

Okay, wake up now! Dozing off on me already are you? I can't say that I blame you. So stop yawning, grab some caffeinated drink, and get ready for more registers!

So assembly does have other registers which you'll need to be familiarized with. Such as pointing registers which are SP (stack pointer), BP (base pointer), and IP (instruction pointer).

When using assembly, you need to understand that a bit is the tiniest data you can incorporate. You'll need to understand the translation for numbers (view the table to the left).
And so on. With assembly language, you might think that it's overwhelming at first, but once you get the hang of it, it's a really great functioning language.

So let's get started already. With assembly, I don't think it would be a good idea for me to just show an example, I should most likely explain some basic concepts. Assmbly uses exponential values for a number. That's why you should have some good grounding in algebra and other mathematical studies. Remember when your teacher told you at the beginning of the year about how important math was? Well she/he wasn't kidding. And when it comes to computer programming, math is the most vital thing. But like I said, assembly treats numbers as if they were in exponential form. So let's say you have a number that's a decimal. Then the right side of the number (everything that's coming after the decimal) would be treated with any number between 0 and 9 multiplied to an increasing negative power of ten. Say what?!? Okay, let's take things slower. Numbers that are in front of the decimal point are considered to be positive, correct? Then that would mean that they would use an increasing power of ten (remember ten with exponents) multiplied to their value (which can be anything from zero to nine). I'm going to hope you understand this factor because it's painfully important with assembly.

Assembly also has the capability to use the binary numbering system. You may have heard of that evil 0 and 1 machine language of using the switches. Well guess what? Get ready to get involved in that. The binary system, unlike the above decimal system, uses the power of 2.

In assembly, there are bit patterns which are just one long string of numbers in ones and zeros. Executable programs run these bit patterns which are stored or are in memory. But assembly is way less stressful than machine language because when the coding is compiled, it converts the instructions to a way that the computer will understand (machine language), but you the human just see it as the coding you typed in. Computers have a different way of looking at things.

When using the hexidecimal code for letters, a zero must always appear first.

I don't mean to bail out on you already, but I won't be able to work on this tutorial for a while. I've been really busy, so for now, the updating of the assembly tutorial will be delayed.

This tutorial was started on Tuesday, July 21. If you'd like to contribute to this tutorial e-mail me and tell me. I will give you credit for what you write along with your banner and a review of your page(s)!