Data types and their definitions

Before we start working with Assembly instructions, we have to know how to define data, or, to be more precise, how to tell the assembler which type of data we are using.

The Flat Assembler supports six built-in types of data and allows us to either define or declare variables. The difference between a definition and a declaration in this case is that when we define a variable we also assign a certain value to it, but when we declare, we simply reserve space for a certain type of data:

Variable definition format: [label] definition_directive value(s)

  • label: This is optional, but addressing an unnamed variable is harder

Variable declaration format: [label] declaration_directive count

  • label: This is optional, but addressing an unnamed variable is harder
  • count: This tells the assembler how many entries of the type specified in declaration_directive it should reserve memory for

The following table shows definition and declaration directives for built-in data types, sorted by size thereof:

Size of data type in bytes

Definition directive

Declaration (reservation) directive

1

db file (includes binary file)

rb

2

dw du (defines unicode character)

rw

4

dd

rd

6

dp df

rp rf

8

dq

rq

10

dt

rt

 

The preceding table lists acceptable data types ordered by their size in bytes, which is in the leftmost column. The column in the middle contains the directives we use in the Assembly code for definition of data of a certain type. For example, if we want to define a byte variable named my_var, then we write the following:

my_var   db  0x5a

Here, 0x5a is the value we assign to this variable. In cases where we do not need to initialize the variable with any specific value, we write this:

my_var db ?

Here, the question mark (?) means that the assembler may initialize the memory area occupied by this variable to any value (which would typically be 0).

There are two directives that require a bit more attention:

  • file: This directive instructs the assembler to include a binary file during the compilation.
  • du: This directive is used just like db is used to define characters or strings thereof, yet it produces unicode-like characters/strings instead of ASCII. The effect is the 0 extension of 8-bit values to 16-bit values. This is rather a convenience directive and has to be overridden when a proper transformation to unicode is required.

Directives shown in the rightmost column are used when we want to reserve space for a range of data entries of a certain type without specifying the values thereof. For example, if we want to reserve space for, let's say, 12 32-bit integers labeled my_array, then we would write the following:

my_array rd 12

The assembler would then reserve 48 bytes for this array, beginning at a place labeled my_array in the code.

Although you will use these directives in the data section most of the time, there is no limitation as to where they may be placed. For example, you may (for whatever purpose) reserve some space within a procedure, or between two procedures, or include a binary file containing precompiled code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset