Previous page Select page Next page

Taking the register

Registers, as we know, are small areas of memory actually inside the CPU. They are lightning fast, even compared with your RAM, and so if you have a piece of information which is frequently used, a register is the best place for it. There are 8 general, 32-bit registers as you can see from the diagram below. In addition, there is another register - the EIP - which holds the instruction currently being executed but, since you can neither read nor write to it, we can ignore it for programming purposes.

Note the EDI, ESI, EBP and ESP registers. As we said, these are 32-bit registers but we can also treat the lower half of each as 16-bit registers with the names as shown (ie without the "E"). The EDI and ESI registers are used to hold the addresses of locations for writing to and reading from memory. EBP and ESP are broadly used for what are called "stack" operations (more on that in a lter chapter) although, with great care (!) they can be used for other purposes. Personally I wouldn't recommend that but, if you like to live life on the edge, you can play around with them. You've been warned!

But the ones you'll use the most are EAX, EBX, ECX and EDX. These are general purpose and they have an extra feature which differentiates them from the other four we've just been speaking about - their 16-bit sections can further be sub-divided into two 8-bit registers. For example, AX can be used as AH and AL, where the "H" and the "L" stand for "high byte" and "low byte", respectively. EAX, particularly, will come in for a lot of work. Why? Well, because Windows functions often pass any return values back to your program via the EAX register. We're going to see just that later in this chapter.

There are fairly accepted ways of using these registers and Jeremy has written a nice little article on it in his goAsm help file. At this point in time, "accepted practice" will mean very little to you as you are not yet familiar with all the ways in which you can use registers. So, I think we can leave that aside for the moment but I strongly recommend that you read his article on the subject when you feel you have enough knowledge to put it into context.

Previous page Select page Next page