Previous page Select page Next page

Dissecting the code

It’s about time, then, that we looked at the assembly which EasyCode generated for us. Much of this will make little sense to you at this point in the game. But what I want to point out here is not the commands but the structure of assembly language programs. Look at the toolbar inside the design window. At the left hand end of the bar, you will see three buttons, as shown here. The first of these displays your editable “helloWorld” window. The second displays the code used to create it and the third, which looks like a little toggle switch, allows you to test it out without actually compiling it. Click the “View code” button and you will see the assembly code which EasyCode generated for you.

There are four main sections to an assembly program:

You are required to declare the first three of these in your program (EasyCode does it for you most of the time) but the fourth is created by goAsm automatically if you make use of any uninitialised data. The assembler also names this section for you, so we can forget it for the moment.

Why do we have these sections? They are required by the assembler to allow it to compile the code correctly. Material in the “Constants” section is taken to be like the speed of light – a value which can be read and used in calculations but cannot be changed. Code in the “Data” section declares values which can be read and used but also changed, like the rate of income tax, for example, which goes up and down (mostly up) with changing government legislation. Uninitialised data represents variables which have no specific values at the point at which the code is compiled. Values will be inserted into these when the program is running (run-time) and goAsm treats these differently, as we now know. The remaining section is “Code”. As you can imagine, any text in here is taken as something which is meant to be executable. These are the commands which your CPU will follow.

Naming these sections is simple. goAsm accepts more than one naming convention in this area but EasyCode uses “.Const”, “.Data” and “.Code”. Stick with those. In a later chapter, I will show you how to write assembly programs and add them to your project. These are called “Modules”. It’s important to note, therefore, that when you write your own assembly code, you can have as many of these sections in your program as you want. If you have, say, ten “.Data” sections scattered throughout your code, goAsm will pick them up and stick them together into one big one before compiling. This also applies to the other section types.

Previous page Select page Next page