Skip to main content

5

5.1 Instruction Aliases

ALIAS line from opcodes/riscv-opc.c

To better diagnose situations where the program flow reaches an unexpected location, you might want to emit there an instruction that’s known to trap. You can use an UNIMP pseudoinstruction, which should trap in nearly all systems. The de facto standard implementation of this instruction is:

  • C.UNIMP: 0000. The all-zeroes pattern is not a valid instruction. Any system which traps on invalid instructions will thus trap on this UNIMP instruction form. Despite not being a valid instruction, it still fits the 16-bit (compressed) instruction format, and so 0000 0000 is interpreted as being two 16-bit UNIMP instructions.
  • UNIMP : C0001073. This is an alias for CSRRW x0, cycle, x0. Since cycle is a read-only CSR, then (whether this CSR exists or not) an attempt to write into it will generate an illegal instruction exception. This 32-bit form of UNIMP is emitted when targeting a system without the C extension, or when the .option norvc directive is used.

5.2 Pseudo Ops

Both the RISC-V-specific and GNU .-prefixed options.

The following table lists assembler directives:

Table 2. Assembler Directives

| Directive | Arguments | Description | | .align | integer | align to power of 2 (alias for .p2align which is preferred - see .align | | .p2align | p2,[pad_val=0],max | align to power of 2 | | .balign | b,[pad_val=0] | byte align | | .file | "filename" | emit filename FILE LOCAL symbol table | | .globl | symbol_name | emit symbol_name to symbol table (scope GLOBAL) | | .local | symbol_name | emit symbol_name to symbol table (scope LOCAL) | | .comm | symbol_name,size,align | emit common object to .bss section | | .common | symbol_name,size,align | emit common object to .bss section | | .ident | "string" | accepted for source compatibility | | .section | [{.text,.data,.rodata,.bss}] | emit section (if not present, default .text) and make current | | .size | symbol, symbol | accepted for source compatibility | | .text | | emit .text section (if not present) and make current | | .data | | emit .data section (if not present) and make current | | .rodata | | emit .rodata section (if not present) and make current | | .bss | | emit .bss section (if not present) and make current | | .string | "string" | emit string | | .asciz | "string" | emit string (alias for .string) | | .equ | name, value | constant definition | | .macro | name arg1 [, argn] | begin macro definition \argname to substitute | | .endm | | end macro definition | | .type | symbol, @function | accepted for source compatibility | | .option | {arch,rvc,norvc,pic,nopic,relax,norelax,push,pop} | RISC-V options. Refer to .option for a more detailed description. | | .byte | expression [, expression]* | 8-bit comma separated words | | .2byte | expression [, expression]* | 16-bit comma separated words | | .half | expression [, expression]* | 16-bit comma separated words | | .short | expression [, expression]* | 16-bit comma separated words | | .4byte | expression [, expression]* | 32-bit comma separated words | | .word | expression [, expression]* | 32-bit comma separated words | | .long | expression [, expression]* | 32-bit comma separated words | | .8byte | expression [, expression]* | 64-bit comma separated words | | .dword | expression [, expression]* | 64-bit comma separated words | | .quad | expression [, expression]* | 64-bit comma separated words | | .float | expression [, expression]* | 32-bit floating point values, see Floating-point literals for the value format. | | .double | expression [, expression]* | 64-bit floating point values, see Floating-point literals for the value format. | | .quad | expression [, expression]* | 128-bit floating point values, see Floating-point literals for the value format. | | .dtprelword | expression [, expression]* | 32-bit thread local word | | .dtpreldword | expression [, expression]* | 64-bit thread local word | | .sleb128 | expression | signed little endian base 128, DWARF | | .uleb128 | expression | unsigned little endian base 128, DWARF | | .zero | integer | zero bytes | | .variant_cc | symbol_name | annotate the symbol with variant calling convention | | .attribute | name, value | RISC-V object attributes, more detailed description see .attribute. | | .insn | see description | emit a custom instruction encoding, see .insn |