Data Constants Declaration

Data Constants Declaration

A data constant declaration in ILAsm has the following syntax:

<data_decl> ::= .data tls ] [<data_label> = ] <data_items>

where <data_label> is a simple name, unique within the module, and

<data_items> ::= { <data_item> [ , <data_item>* ] }   <data_item>

where

<data_item> ::= <data_type> [ ( <value> ) ] [ [ <count> ] ]

Data constants are emitted to the .sdata section or the .tls section, depending on the presence of the tls keyword, in the same sequence in which they were declared in the source code. The unlabeled data declarations can be used for padding between the labeled data declarations and probably for nothing else, since without a label it’s impossible to map a field to this data. Unlabeled—or, more precisely, unreferenced—data might not survive round-tripping (disassembly-reassembly) because the IL Disassembler outputs only referenced data.

The nonterminal symbol <data_type> specifies the data type. (See Table 8-2.) The data type is used by the ILAsm compiler exclusively for identifying the size and byte layout of <value> and is not emitted as any part of metadata or the data itself. Having no way to know what the type was intended to be when the data was emitted, the IL Disassembler always uses the most generic form, a byte array, for data representation.

If <value> is not specified, the data is initialized to a default value (usually a value with all bits set to zeros). Thus it is still “initialized data” in terms of the PE file structure—meaning that this data is part of the PE file disk image.

The optional <count> in square brackets indicates the repetition count of the data item. Here are some examples:

.data tls T_01 = int32(1234)   // 4 bytes in .tls section, value 0x000004D2 .data tls int32  // 4 bytes padding in .tls section, value doesn't matter .data D_01 = int32(1234)[32] // 32 4-byte integers in .sdata section,                               // Each equal to 0x000004D2

Table 8-2  Types Defined for Data Constants 

Data Type

Size

Value

Comments

float32

4 bytes

Floating-point, single precision

If an integer value is used, it is converted to floating-point. If the value overflows float32, the ILAsm compiler issues a warning.

float64

8 bytes

Floating-point, double precision

If an integer value is used, it is converted to floating-point.

int64

8 bytes

8-byte signed integer

int32

4 bytes

4-byte signed integer

If the value overflows int32, the ILAsm compiler issues a warning.

int16

2 bytes

2-byte signed integer

If the value overflows int16, the ILAsm compiler issues a warning.

int8

1 byte

1-byte signed integer

If the value overflows int8, the ILAsm compiler issues a warning.

bytearray

var

Sequence of two-digit hexadecimal numbers, without the 0x prefix

The value cannot be omitted since it defines the size. The repetition parameter ([<count>]) cannot be used.

char*

var

Composite quoted string

The value cannot be omitted since it defines the size. The repetition parameter ([<count>]) cannot be used. The string is converted to Unicode before being emitted to data.

&

4 bytes

Another data label

Data-on-data; the data containing the value of the unmanaged pointer—the virtual address—of another named data segment. The value cannot be omitted, and the repetition parameter ([<count>]) cannot be used. The referenced data segment must be declared before being referenced in a data-on-data declaration.



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net