  Objectives

The aim of this chapter is to help you understand how to use CPU registers to handle communication with the Windows operating system. To do this, you will need to be able to:

• Manipulate values in binary, decimal and hexadecimal
• Understand the way in which data can be "chunked"
• Understand the use of the CPU Registers
• Use different types of data in your programs
• Create your own event handler
• Use the Win32 help manual
• Call a Windows function
• Call an EasyCode function
• Manipulate a string

Now that we are reasonably comfortable with compiling programs in EasyCode, let's move on to the heart of assembly programs - number systems. Yes, I know this chapter is called "Registers and data" but "Data and registers" didn't sound as good! We need to deal with numbers first or the section on registers won't make as much sense. If you are already fully familiar with binary and hexadecimal and how to covert between these and decimal, you could skip over this section. For the rest of you, this is really rather important, so I recommend you take a look. By all means, skim through it and re-visit it later, but you should have a basic idea of what's going on with numbers if you are to understand what the registers are doing for us.

But what if we wanted a number larger than 10? Well, we can look upon numbers as being made up of an infinite series of empty boxes, each of which is capable of holding a single digit in the range 0-9. For example, the "number one hundred and fifty-six" would look like this: We know that the six is just a six but that the five stands for "5 x 10" and the one is really "1 x 100" - but how? Through years of practice in school and in adult life, we get to be pretty good at looking at a number and subconsciously working out the value of the maximum occupied box - is it 100? 1000? 10000? - and then going back down the line, giving scale to all the other digits until we can state the value of the entire number. Anything up to a million, we can usually handle pretty quickly but once it goes beyond that number things start to slow down. Take, for example, this number - 1001236745699 - time yourself to see how long it takes you to "decode" it and note how you did it. You had to say "that one is Units, that one's Tens, that one's Hundreds ..." and so on until you had reached the leftmost (highest) digit. Once you had done that, you could move back down the line again. This dependence on calculating the highest digit in a number has led to the convention of calling the leftmost digit the most significant and the rightmost the least significant.

Let's take another look at our first number: The powers of ten above the boxes show the value by which the contents of the box must be multiplied to give the correct number. So, the "1" must be multiplied by 10 x 10 (two tens multiplied together), the "5" by 10 (one ten) and the "6" by no tens at all. This will give us:

1 x 100 + 5 x 10 + 6 = 156

Easy! Let's try something more difficult, say, 15134. Put each digit into a box as we have done above and we should get:

 1 x 10000 5 x 1000 1 x 100 3 x 10 4

We say, then, that 10 is the number base and that the digit in each box is multiplied by the base raised to the power of "n", where "n" is the box's position in the number line, starting from zero (on the right) and going in steps of one to infinity (on the left). This would give us 1 x 16 (4 twos multiplied together) + 0 x 8 (3 twos multiplied together) + 0 x 4 (2 twos multiplied together) + 1 x 2 + 1, thus giving us 1910 in decimal (note the little number at the end which denotes which base we are in). Prove to yourself that this approach works by taking the binary number we have just created and turn it back into decimal.

The leftmost (most significant) bit of a chunk of data is regarded as the "sign" bit when we choose to handle the values as signed numbers. In the case of bytes, this means bit 7 but there are larger chunks as we shall shortly see. A "word", for example, is two bytes joined together to make 16 bits (0-15). In the case of a word, the sign bit would be bit 15. Making a number negative is a little more complicated than you would think. The process is as follows:

1. Change all the ones to zeros, and vice versa.  