• Keine Ergebnisse gefunden

Conditional Assembly Instructions

Chapter 8 ANSI Library

9.5 Preprocessor Pseudo-Instructions

9.5.4 Conditional Assembly Instructions

(#ifdef ... #else ... #endif, #ifndef... #else ... #endif)

A conditional assembly instruction determines whether assembling should be performed within the specified range, dependent on whether the specified name (Define name) is defined or not.

Instruction formats

Format 1) #ifdef <Name>

<Statement string 1>

[#else

<Statement string 2>]

#endif

If the <Name> is defined, <Statement string 1> will be subjected to the assembling.

If the <Name> is not defined, and #else ... <Statement string 2> is described, then <Statement string 2> will be subjected to the assembling. #else ... <Statement string 2> can be omitted.

Format 2) #ifndef <Name>

<Statement string 1>

[#else

<Statement string 2>]

#endif

If the <Name> is not defined, <Statement string 1> will be subjected to the assembling.

If the <Name> is defined, and #else ... <Statement string 2> is described, <Statement string 2> will be subjected to the assembling. #else ... <Statement string 2> can be omitted.

<Name>:

• Conforms to the restrictions on Define name. (See #define.) <Statement string>:

• All statements, excluding conditional assembly instructions, can be described.

Sample description:

#ifdef TYPE1

ld.w %r1, 0x12

#else

ld.w %r1, 0x13

#endif Name definition

Name definition needs to have been completed by either of the following methods, prior to the execution of a conditional assembly instruction:

1) To define by using the startup option (-d) of the pp33.

Example: pp33 -d TYPE1 sample.s

2) To define in the source file by using the #define instruction.

Example: #define TYPE1

The #define statement is valid even in a file to be included, provided that it goes before the conditional assembly instruction that uses its Define name. A name defined after a conditional assembly instruction will be regarded as undefined.

When a name is going to be used only in conditional assembly, no substitute character string needs to be specified.

CHAPTER 9: PREPROCESSOR

E0C33 FAMILY EPSON 117

Expansion rule

A statement string subjected to the assembling is expanded according to the expansion rule of the other preprocessor instructions. (If no preprocessor instruction is contained, the statement will be output in a file as is.)

Statement strings not subjected to the assembling are delivered as comments.

Precautions

• A name specified in the condition is evaluated with discrimination between uppercase and lowercase. The condition is deemed to be satisfied only when there is the same Define name defined.

• The #ifdef (#ifndef) instruction cannot be used for a statement string in a conditional assembly instruction, but the #define, #macro and #include instructions can be employed.

CHAPTER 9: PREPROCESSOR

9.6 Operators

An expression that consists of operators and numbers can be used for specifying an immediate data.

The pp33 handles expressions in signed 32-bit data.

When writing expressions, do not insert a space between a term and an operator.

Types of operators

Examples

+ Addition, Plus sign +0xff, 1+2

- Subtraction, Minus sign -1+2, 0xfff-0b111

* Multiplication 0xf*5

/ Division 0x123/0x56

%% Residue 0x123%%0x56

>> Shifting to right 1>>2

<< Shifting to left 0x113<<3

& Bit AND 0b1101&0b111

| Bit OR 0x123|0xff

^ Bit XOR 12^35

~ Bit inversion ~0x1234

^H Acquires bit field (31:19) 0x1234^H

^M Acquires bit field (18:6) 0x1234^M

^L Acquires bit field (5:0) 0x1234^L

^AH Acquires bit field (25:13) 0x1234^AH

^AL Acquires bit field (12:0) 0x1234^L

( ) Parenthesis 1+(1+2*5)

Priority

The operators have the priority shown below. If there are two or more operators with the same priority in an expression, the preprocessor calculates the expression from the left.

1. ( ) High priority

2. + (plus sign), - (minus sign), ~ ↑

^H, ^M, ^L, ^AH, ^AL 3. *, /, %%

4. +, -

5. <<, >>

6. &

7. ^ ↓

8. | Low priority

Terms in expression

The following contents can be written in the terms of an expression.

• Binary, decimal, or hexadecimal number in the effective range of values represented by 32 bits Unsigned integer: 0 to 4294967295 (0x0 to 0xffffffff)

Signed integer: 0 to 2147483647 (0x0 to 0x7fffffff), -1 to -2147483648 (0xffffffff to 0x80000000)

• Define names defined for numbers (names defined by #define)

• Symbol

If the symbol is not a Define name, the expression is limited to the following format:

SYMBOL [+SYMBOL...] + numeric expression or SYMBOL [+SYMBOL...] - numeric expression

CHAPTER 9: PREPROCESSOR

E0C33 FAMILY EPSON 119

Examples

#define BAR 0x1

ld.w %r0, BAR+2 ...ld.w %r0, 0x3

xcall LABEL+BAR*2 ...xcall LABEL+0x2

xld.w %r1, [FOO+BAR+1] ...xld.w %r1, [FOO+0x2]

xld.w %r1, [BAR+FOO+1] ...An error will result if FOO is not a Define name.

Precautions

• Since the operation is internally performed as 32 signed bits, caution is required depending on the type of operation.

Pay attention to the calculation results of the >>, / and %% operators using hexadecimal numbers.

Examples:

#define NUM1 0xfffffffe/2 ...-2/2 = -1 (0xffffffff)

The / and %% operators can only be used within the signed

32-bit range.

#define NUM2 0xfffffffe>>1 ...-2>>1 = -1 (0xffffffff)

Mask as (0xfffffffe>>1)&0x7fffffff.

• The calculation result is delivered as a decimal number with a minus sign if it is negative, or a hexadecimal number if it is positive.

Eamples:

add %r0, -2+1 ...It will be expanded as "add %r0, -1".

add %r0,(-2+1)&0x3f ...It will be expanded as "add %r0, 0x3f".

• Do not insert a space or a TAB between an operator and a term (number, Define name).

Examples:

ld.w %r0, 1+1 ...OK

ld.w %r0, 1 + 1 ...NG

ld.w %r0, (1+NUM1)*2 ...OK ld.w %r0, (1 + NUM1)*2 ...NG

CHAPTER 9: PREPROCESSOR

9.7 Debugging Information

When the startup option -g is specified ([debug info] checked on the work bench), the pp33 inserts assembler pseudo-instructions in the output file, as the debugging information designed to correspond with the assembly source level debugging.

Notes: • This debugging information is necessary to perform debugging on the Debugger db33, with the assembly source displayed.

• Make sure the debugging information is created by only specifying the -g option, and not by any other method. Also, be sure not to correct the debugging information that is output.

Corrections could cause the as33, lk33, db33 or dis33 to malfunction.

• Unless the -g option is specified in the lk33 even though it may be specified in the pp33 (same applies for gcc33), all debugging information will be cut during linkage.

• The source information created by specifying the -g option in the pp33 is not cut even when the -g option is not specified in the as33.

• The assembler level symbol information (symbol names and addresses only) is created when the -g option is specified in the as33.

Assembler pseudo-instructions to be delivered

The following three types of debugging pseudo-instructions are delivered. The characters other than those in the underlined parts are fixed.

1) .file "PATH_NAME"

Indicates the beginning of a file. Inserted at top of the current file or in the start position of an included file. PATH_NAME is the file path name.

2) .endfile

Indicates the end of a file. Inserted at the end of the current file

The .file pseudo-instruction indicating the restart of the original file is inserted at the end of the include file. The .endfile pseudo-instruction is not inserted, however.

3) .loc LINE_NO

Indicates the line information of the source file. Added only to the mnemonic statement (line assembled to the object code). LINE_NO is a source line number.

Sample output

Startup command: pp33 -g base_file.s Before processing:

• Source file "base_file.s"

; file start

#include "inc.def"

ld.w %r1, [%r7]

ld.w [%r3], %r1

• Included file "inc.def"

; This is an empty file.

After processing:

• Assembly source file "base_file.ms"

.file "base_file.s" Start of "base_file.s"

; file start (Debugging information is not added to comments.) ;#include "inc.def"

.file "inc.def" Start of "inc.def"

; This is an empty file.

.file "base_file.s" Resuming of "base_file.s"

.loc 3 Line No. 3 (base_file.s)

ld.w %r1, [%r7]

.loc 4 Line No. 4 (base_file.s)

ld.w [%r3], %r1

.endfile End of "base_file.s"

CHAPTER 9: PREPROCESSOR

E0C33 FAMILY EPSON 121