Previous page Select page Next page

What is data?

You can see from your code that you have no constants in this program but there is something in the data section. What we need to do now, therefore, is to discuss what we mean by the word “data”.

Imagine a vast automated warehouse, a bit like the one at the end of the first “Indiana Jones” movie, which contains row upon row of storage boxes. These ones have no “backs” to them, so whenever anyone "stores" something in them, it pushes out anything that was already in there. Consider this to be like Windows memory. If we want to retrieve some information (the bubbles in my illustration) from this warehouse, we will have to have some way of telling the system where, in this vast warehouse, it was stored in the first place. Obviously, there would be some numbering system for the boxes. In programming, this is done by means of variable names (called labels in the context of assembler). The operating system finds the first available box, sticks the variable name you have provided on to it and then inserts your value (the bubble). To retrieve the bubble, you provide the variable name, the operating system looks up exactly where the box with that name is located and the bubble gets retrieved.

But there’s something else. To make the best use of the warehouse space (even although it is enormous), the storage boxes are of different sizes and shapes to best suit the types of things that can be stored there. Thus, if we give the warehouse a postcard to store, we don’t want it to place it in a box large enough for the Ark of the Covenant (and vice versa!). So, when we first ask the operating system to assign a storage box for us (known as declaring the variable), we must also tell it what type of thing will be stored in it.

When we are programming in assembler, we’re talking about two “warehouses” – the huge one which is the computer’s memory and a smaller one for fast “FedEx”-type storage – the CPU’s registers. I’ll begin discussing these in the next chapter but I want to talk about the types right now so that we can understand the code we’re currently looking at.

Look at our data section again. We have one data item and it’s called “MESSAGES”. This “variable” is made up of 4 double words (a double word is made up of 4 bytes and is indicated by the mnemonic “DD”). The first of these is the Windows message “WM_CREATE” and the second is the location of the code which must react to that message. The third byte is the value for the Windows message “WM_CLOSE” and the fourth is the code to handle that message. Note how you can split these over two lines for readability. We could have placed them all on one line, separated by commas:


Note that we must remove the second “DD” or it will be an illegal line. Try this out for yourself in EasyCode and then re-build. You’ll see that it works perfectly well. In fact, goAsm offers you a range of ways in which you can express your data needs. We will not be covering all of them or I would simply be re-creating goAsm’s own documentation. I’ll deal with what we need when we need it. And that will be in the next chapter. For now, we should understand what the messages are for.

Previous page Select page Next page