官术网_书友最值得收藏!

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:

 

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.

主站蜘蛛池模板: 长兴县| 黄大仙区| 仙游县| 建阳市| 西华县| 安阳市| 农安县| 瑞昌市| 长阳| 桐城市| 商洛市| 黎川县| 镇远县| 肥西县| 郧西县| 松桃| 玉田县| 邻水| 二连浩特市| 金川县| 新津县| 阜城县| 呼图壁县| 十堰市| 天津市| 马边| 凉城县| 钟祥市| 安义县| 如东县| 红桥区| 通州市| 镇远县| 同仁县| 南雄市| 饶阳县| 屏山县| 靖安县| 宜兰县| 呼和浩特市| 佛坪县|