Skip to main content

IAR Embedded Workbench for RISC-V 3.40

Predefined symbols

In this section:

These predefined symbols are available:

Symbol

Value

__BASE_FILE__

The name of the base source file being assembled (string).

__BUILD_NUMBER__

A unique integer that identifies the build number of the assembler currently in use. The build number does not necessarily increase with an assembler that is released later.

__DATE__

The current date in dd/Mmm/yyyy format (string).

__FILE__

The name of the current source file (string).

__IAR_SYSTEMS_ASM__

IAR assembler identifier (number). The current value is 9. Note that the number could be higher in a future version of the product. This symbol can be tested with #ifdef to detect whether the code was assembled by an assembler from IAR.

__IASMRISCV__

An integer that is set to 1 when the code is assembled with the IAR Assembler for RISC-V.

__LINE__

The current source line number (number).

__riscv

An integer that is set to 1 when the code is assembled for RISC-V.

__riscv_32e

An integer that is set to 1 when the code is assembled for a RISC-V core with the E extension.

__riscv_a

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the A extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_arch_test

An integer that is set to 1 when the assembler supports architecture extension test macros. The value of an architecture extension test macro is computed based on its version number, using this formula:

major_v * 1000000 + minor_v * 1000 + revision_v

Example:

If the F extension is version 2.2, __riscv_f is defined to 2002000.

If the B extension is version 0.92, __riscv_b is defined to 92000.

__riscv_atomic

An integer that is set to 1 when the code is assembled for a RISC-V core with the A extension. This symbol is deprecated. Use the symbol __riscv_a instead.

__riscv_b

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the B extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_bitmanip

An integer that is set to 1 when the code is assembled for a RISC-V core with the B extension. This symbol is deprecated. Use the symbol __riscv_b instead.

__riscv_c

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the C extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_cmodel_medany

An integer that is set to 1 when the code is assembled for the Medany code model.

__riscv_cmodel_medlow

An integer that is set to 1 when the code is assembled for the Medlow code model.

__riscv_compressed

An integer that is set to 1 when the code is assembled for a RISC-V core with the C extension. This symbol is deprecated. Use the symbol __riscv_c instead

__riscv_d

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the D extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_div

An integer that is set to 1 when the code is assembled for a RISC-V core with the M extension. This symbol is deprecated. Use the symbol __riscv_m instead.

__riscv_dsp

An integer that is set to 1 when the code is assembled for a RISC-V core with the Xandesdsp extension.

__riscv_e

This is an architecture extension test macro. It is defined when the code is assembled for the RV32E base instruction set. The value of the symbol is an integer that identifies the version of the instruction set.

__riscv_f

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the F extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_fdiv

An integer that is set to 1 when the code is assembled for a RISC-V core with the F extension. This symbol is deprecated. Use one of the symbols __riscv_d or __riscv_f instead.

__riscv_flen

An integer that is set to 32 when the code is assembled for a RISC-V core with the F (but not the D) extension, and to 64 when the code is assembled for a core with the FD extensions (implicitly or explicitly). If the code is assembled for neither extension, this symbol is undefined.

__riscv_fsqrt

An integer that is set to 1 when the code is assembled for a RISC-V core with the F extension. This symbol is deprecated. Use one of the symbols __riscv_d or __riscv_f instead.

__riscv_i

This is an architecture extension test macro. It is defined when the code is assembled for the RV32I base instruction set. The value of the symbol is an integer that identifies the version of the instruction set.

__riscv_m

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the M extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_mul

An integer that is set to 1 when the code is assembled for a RISC-V core with the M extension. This symbol is deprecated. Use the symbol __riscv_m instead.

__riscv_muldiv

An integer that is set to 1 when the code is assembled for a RISC-V core with the M extension. This symbol is deprecated. Use the symbol __riscv_m instead.

__riscv_p

This is an architecture extension test macro. It is defined when the code is assembled for a RISC-V core with the P extension. The value of the symbol is an integer that identifies the version of the extension.

__riscv_xbcountzeroes

An integer that is set to 1 when the code is assembled for a RISC-V core with the standard name extension Xbcountzeroes (a subset of the standard extension Zbb with count leading/trailing zero instructions).

__riscv_xlen

An integer that is set to the integer register size of the current base instruction set. This is 32 for RV32 and 64 for RV64..

__riscv_zba

An integer that is set to the version number of the B extension when the code is assembled for a RISC-V core with the standard name extension Zba (“base” bit manipulation instructions).

__riscv_zbb

An integer that is set to the version number of the B extension when the code is assembled for a RISC-V core with the standard name extension Zbb (“best of” bit manipulation instructions).

__riscv_zbc

An integer that is set to the version number of the B extension when the code is assembled for a RISC-V core with the standard name extension Zbc (“carry-less” bit manipulation instructions).

__riscv_zbpo

An integer that is set to the version number of the P extension when the code is assembled for a RISC-V core with the standard name extension Zbpbo (bit manipulation instructions required by the P extension).

__riscv_zbs

An integer that is set to the version number of the B extension when the code is assembled for a RISC-V core with the standard name extension Zbs (“single bit” bit manipulation instructions).

__riscv_zdinx

An integer that is set to the version number of the Zdinx extension when the code is assembled for a RISC-V core with the standard name extension Zdinx (double-precision floating-point in integer registers).

__riscv_zfinx

An integer that is set to the version number of the Zfinx extension when the code is assembled for a RISC-V core with the standard name extension Zfinx (single-precision floating-point in integer registers).

__riscv_zicbom

An integer that is set to the version number of the RISC-V CMO standard when the code is assembled for a RISC-V core with the standard name extension Zicbom (cache block management operations).

__riscv_zicbop

An integer that is set to the version number of the RISC-V CMO standard when the code is assembled for a RISC-V core with the standard name extension Zicbop (cache block prefetch operations).

__riscv_zicboz

An integer that is set to the version number of the RISC-V CMO standard when the code is assembled for a RISC-V core with the standard name extension Zicboz (cache block zero operations).

__riscv_zpsfoperand

An integer that is set to the version number of the P extension when the code is assembled for a RISC-V core with the standard name extension Zpsfoperand (P extension instructions for accessing register pairs).

__riscv_zpn

An integer that is set to the version number of the P extension when the code is assembled for a RISC-V core with the standard name extension Zpn (P extension instructions that are not included in Zbpbo or Zpsfoperand).

__TIME__

The current time in hh:mm:ss format (string).

__VER__

The version number in integer format; for example, version 4.17 is returned as 417 (number).

Table 118. Predefined symbols  


Including symbol values in code

Several data definition directives make it possible to include a symbol value in the code. These directives define values or reserve memory. To include a symbol value in the code, use the symbol in the appropriate data definition directive.

For example, to include the time of assembly as a string for the program to display:

            name    timeOfAssembly
            extern  printStr
            public  printTime
            rseg    `,text`:CODE(2)

printTime   lui     a0, %hi(time)        ; Load address of time
            addi    a0, a0, %lo(time)
            tail    printStr             ; Jump to string output 
                                         ; routine.
time        dc8     __TIME__             ; String representing 
                                         ; the time of assembly.
            end
Testing symbols for conditional assembly

To test a symbol at assembly time, use one of the conditional assembly directives. These directives let you control the assembly process at assembly time.

For example, if you want to assemble separate code sections depending on whether you are using an old assembler version or a new assembler version, do as follows:

#if (__VER__ > 300)                 ; New assembler version
;…
;…
#else                               ; Old assembler version
;…
;…
#endif

For more information, see Conditional assembly directives.