# Assembler The Hexagon assembler translates Hexagon assembly language into object code. Object files are stored in ELF format. The Hexagon assembler is mostly compatible with the syntax and directives supported in the GNU assembler, and it supports all features such as macros, conditional text, and include files. ## Command To start the assembler from the command line: hexagon-llvm-mc -filetype=obj [option...] [input_file...] Copy to clipboard Where `option` is one or more of the options in [Options](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-options). Note Except for the different command name and the required option, `-filetype=obj`, the Hexagon assembler is invoked like the GNU assembler. ## Options Option names can be truncated if they uniquely identify the option. [Assembler information](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-assembler-information) -help -help_hidden -version Copy to clipboard [Input and output files](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-input-and-output-files) -filetype=(asm|null|obj) -main-file-name=string -o Copy to clipboard [Assembly translation](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-assembly-translation) -as-lex -assemble -disable-cfi -I= -L -mno-compound -mno-fixup -mno-pairing -n Copy to clipboard [Code generation](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-code-generation) -code-model=(default|small|kernel|medium|large) -g -mc-no-exec-stack -mc-relax-all -relocation-model=(default|static|pic|dynamic-no-pic) Copy to clipboard [Assembler messages](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-assembler-messages) -fatal-assembler-warnings -mfalign-warn -mfalign-warn-instruction -mfalign-warn-packet Copy to clipboard [Assembly output](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-assembly-output) -disassemble -hdis -mdis -output-asm-variant= -show-encoding -show-inst -show-inst-operands -stats Copy to clipboard [Target](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-target) -mv68 | -mv69 -mv71 | -mv71t | -mv73 | -mv75 | -mv77 | -mv79 -arch= -mattr=, <+a2>, <-a3> -triple= Copy to clipboard ### Assembler information -help Copy to clipboard Display the common assembler options. -help_hidden Copy to clipboard Display all assembler options. -version Copy to clipboard Display the assembler release version. ### Input and output files -filetype=(asm|null|obj) Copy to clipboard Output file type. - `asm`: Assembly file (`*.s`). (Default) - `null`: No output file (used for timing purposes). - `obj`: Hexagon object file (`*.o`) -main-file-name= Copy to clipboard Name of input file to be treated as primary program file. -o Copy to clipboard Output file name. ### Assembly translation -as-lex Copy to clipboard Lexically scan tokens from the specified `*.s` file. -assemble Copy to clipboard Assemble the specified `*.s` file. (Default: enabled). -disable-cfi Copy to clipboard Ignore any `.cfi_*` directives in the assembly source code. -I= Copy to clipboard Path name used to search for assembly include files. (Default: current directory). -L Copy to clipboard Keep temporary symbols in generated symbol table. -mno-compound Copy to clipboard Disable searching for Hexagon compound instructions during assembly. -mno-fixup Copy to clipboard Disable fixing resolved relocations during assembly. -mno-pairing Copy to clipboard Disable searching for Hexagon duplex instructions during assembly. -n Copy to clipboard Do not assume assembly file starts in the text section. ### Code generation -code-model=(default|small|kernel|medium|large) Copy to clipboard This option is accepted by the assembler, but it is ignored. -g Copy to clipboard Generate DWARF debug information for assembly source files. -mc-no-exec-stack Copy to clipboard This option is accepted by the assembler, but it is ignored. -mc-relax-all Copy to clipboard Relax all code fix-ups. -relocation-model=(default|static|pic|dynamic-no-pic) Copy to clipboard This option is accepted by the assembler, but it is ignored. ### Assembler messages -fatal-assembler-warnings Copy to clipboard Treat warning messages as errors. -mfalign-warn Copy to clipboard Warn when there is both `.falign` packet and instruction activity. Note This message is effective only for the standalone `hexagon-llvm-mc` assembler or when `-fno-integrated-as` is passed to `hexagon-clang`. -mfalign-warn-instruction Copy to clipboard Warn when there is `.falign` instruction activity only. Note This message is effective only for the standalone `hexagon-llvm-mc` assembler or when `-fno-integrated-as` is passed to `hexagon-clang`. -mfalign-warn-packet Copy to clipboard Warn when there is `.falign` packet activity only. Note This message is effective only for the standalone `hexagon-llvm-mc` assembler or when `-fno-integrated-as` is passed to `hexagon-clang`. ### Assembly output **-disassemble Copy to clipboard Disassemble strings of hexadecimal bytes. -hdis Copy to clipboard Disassemble strings of hexadecimal bytes, printing immediate values in hexadecimal format. -mdis Copy to clipboard Disassemble strings of hexadecimal bytes, marking up the disassembled code. -output-asm-variant=uint Copy to clipboard Syntax variant to use for printing output. To list the possible values, run the assembler with the `-version` option. -show-encoding Copy to clipboard Display instruction encodings. -show-inst Display internal instruction representations. Copy to clipboard -show-inst-operands Display instruction operands as they are parsed. Copy to clipboard -stats Copy to clipboard Enable statistics output from program. ### Target -mv68 -mv69 -mv71 -mv71t -mv73 -mv75 -mv77 -mv79 Copy to clipboard Specify the Hexagon processor version for which the assembler will generate code. Note For more information on these processor versions, see the *Qualcomm Hexagon Programmer’s Reference Manual*. Note Not all of the `-mvX` options are supported in a specific Hexagon tools release. The default option setting is also release-specific. For more information, see [Processor versions](https://docs.qualcomm.com/doc/80-N3040-23/topic/utilities-ug-overview.html#hu-processor-versions). -arch= Copy to clipboard Target processor architecture. To list the possible values, run the assembler with the `-version` option. -mattr=, <+a2>, <-a3> Copy to clipboard Target-specific attributes. To list the possible values, run the assembler with the `-mattr=help` option. -triple= Copy to clipboard Target triple. To list the possible values, run the assembler with the `-version` option. Note For more information on processor versions, see the *Qualcomm Hexagon Programmer’s Reference Manual*. ## Assembly language basic syntax ### Symbols A symbol consists of the following characters: - `A ... Z`, `a ... z` - `0 ... 9` - `_`, `.`, or `$` Symbols must begin with a letter and are case-sensitive. ### Whitespace Whitespace is defined as one or more blank characters or tab characters. It is used in assembly code to separate symbols. Theassembler interprets whitespace as a single space character. Note Whitespace does not appear in character constants. ### Keywords Keywords are symbols that are reserved by the assembler and cannot be redefined in the assembly code. Registers, assembly language instructions, and assembly directive parameters are all defined as keywords. ### Directives Assembler directives are commands that are embedded in the assembly code. They are used to declare items such as constants and external symbols, and to control assembler features such as macros and include files. Directives always begin with a period character (.) immediately followed by the directive name and (optionally) one or more parameters. The names are case-sensitive. The parameters are delimited by whitespace. For example: .set const_val, 1 .include “myfile.s” Copy to clipboard For more details on directives, see [Directives](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives). ### Numbers Numbers can be expressed in several numeric formats. The formats are specified with the number’s prefix character. See the following table for examples. | Format | Prefix | Example | | --- | --- | --- | | Binary | 0b or 0B | `0b1111` | | Octal | 0 | `077` | | Decimal | non-0 digit | `1028` | | Hexadecimal | 0x or 0X | `0Xffff` | | Floating point | 0e or 0E | `0e3.14159E-3` | Floating point numbers can include the following elements: - A sign character (+ or -) - An integer part that consists of 0 or more decimal digits - A fractional part that consists of a period (.) followed by 0 or more decimal digits - An exponent part that consists of the following elements: - The prefix E or e - A sign character (+ or -) - One or more decimal digits An integer or fractional part is required, while all the other elements are optional. ### Characters String constants are delimited by a pair of double-quote characters (“). For example: "mydata" Copy to clipboard Special characters can be used in characters and strings by prefixing them with a backslash character (\). The following example represents a single backslash, where the first backslash acts as the prefix character for the second: \\ Copy to clipboard Note When used in a numeric expression, the value of a character constant is its 8-bit ASCII code value. The following table shows escape characters to use in characters and strings. | Code | Character | | --- | --- | | `\b` | Backspace | | `\f` | Form feed | | `\n` | Newline | | `\r` | Return | | `\t` | Tab | | `\\` | Backslash | | `\”` | Double quote | | `\NNN` | Octal character value, where `NNN` specifies three octal digits | | `\xhex...` | Hexadecimal character value, where `hex...` specifies N hexadecimal digits | ### Expressions Expressions consist of one or more symbols (representing numeric or address values) that are operated on by one or more operators. Expressions can be used wherever numeric or address values are allowed, including variables and instructions. Note An expression must evaluate to either an absolute value or an offset into a section (see [Sections](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-sections)). Otherwise, it will be flagged with an error message. ### Operators Operators are characters that represent arithmetic functions such as addition or multiplication. Prefix operators accept a single operand, which must be an absolute value. The result is absolute. | Operator | Description | | --- | --- | | `-` | Two’s complement arithmetic negate | | `~` | Bitwise logical NOT | Infix operators accept two operands: + and -. Either operator can operate on relocatable values. For all the other infix operators, the operand values must be absolute and the result is absolute. The following table describes the infix operators. | Operator | Description | Precedence | | --- | --- | --- | | `*` | Multiply | High | | `/` | Divide | High | | `%` | Remainder | High | | `<`


`<<` | Shift left | High | | `>`


`>>` | Shift right | High | | `|` | Bitwise inclusive OR | Intermediate | | `&` | Bitwise AND | Intermediate | | `^` | Bitwise exclusive OR | Intermediate | | `!` | Bitwise OR NOTE | Intermediate | | `-` | Two’s complement arithmetic negate | Low | | `~` | Bitwise logical NOT | Low | | | | | | | | | | | | | | | | | The infix operators have differing precedence—operators with the highest precedence are evaluated first in an expression, and operators with equal precedence are evaluated left to right in an expression. ### Relocatable operands If an absolute operand is added to a relocatable operand, the result belongs to the section of the relocatable operand. Two relocatable operands cannot be added if they belong to different sections. If an absolute operand is subtracted from a relocatable operand, the result belongs to the section of the relocatable operand. If both operands are relocatable and in the same section, the result of a subtraction is absolute. Two relocatable operands cannot be subtracted if they belong to different sections. ### Statements A statement is considered to be equivalent to one line in the assembly source code. It is terminated with a newline character (`\n`). statement \n Copy to clipboard A single statement can span multiple lines in the assembly source code if you place a backslash character (`\`) at the end of each line. Place the newline character at the end of the last line. statement \ continued statement \ last line of statement \n Copy to clipboard Note Every statement in an assembly source file (including the last statement in the file) must be terminated with a newline character. ### Comments Delimited comments begin with the `/*` character sequence and end with `*/`. They can span multiple lines and cannot be nested. For example: /* delimited comment */ Copy to clipboard Line comments begin with `//` and end at the newline character on the current line. For example: code // line comment \n Copy to clipboard ## Sections > > > Assembly language programs are organized into collections of units known as *sections*. For example: .section .text // Hexagon instructions .section .data // variable declarations Copy to clipboard ### Predefined sections Each section is defined to occupy a range of consecutive addresses. When the linker merges object files into a single executable image, it relocates the starting address of each section in the object files so the sections do not overlap in memory. - A program contains a minimum of three sections: - `text` — Contains program code and is assigned to address 0 - `data` — Is relocated to immediately follow the text section in memory - `bss` — Is relocated to follow the data section - The `sdata` and `sbss` sections contain data (such as common symbols) that is assigned to the global data area. - The `ebi_*`, `tcm_*`, and `smi_*` sections contain data that is assigned to system-specific memories with defined cache properties. For more information, see the *Qualcomm Hexagon Programmer’s Reference Manual*. The following table shows the assembly sections in an assembly program. | Section name | Description | | --- | --- | | `.text`


`.data`


`.rodata` | Program code and data.


`.rodata` is used to store read-only data. | | `.bss` | Uninitialized variables or common data.


`.bss` does not occupy any space in an object file because the section data is always initialized to zero when the section is loaded into memory. | | `.sdata` | Global `.data` section | | `.sbss` | Global `.bss` section | | `.ebi_code_cached` |
Code

  • ebi = external bus interface


  • tcm = tightly-coupled memory


  • smi = stacked memory interface


| | `.tcm_code_cached` |
Code

  • ebi = external bus interface


  • tcm = tightly-coupled memory


  • smi = stacked memory interface


| | `.smi_code_cached` |
Code

  • ebi = external bus interface


  • tcm = tightly-coupled memory


  • smi = stacked memory interface


| | `.ebi_data_cached` | Data (cached) | | `.tcm_data_cached` | Data (cached) | | `.smi_data_cached` | Data (cached) | | `.ebi_data_cached_wt` | Data (write-through cached) | | `.tcm_data_cached_wt` | Data (write-through cached) | | `.smi_data_cached_wt` | Data (write-through cached) | | `.ebi_data_uncached` | Data (uncached) | | `.tcm_data_uncached` | Data (uncached) | | `.smi_data_uncached` | Data (uncached) | | | | | | | If sections are not explicitly declared in the source code, the assembler automatically assigns the program code and data to EBI memory. The linker typically assigns all sections of the same type to occupy contiguous addresses in memory. This can be changed by creating a linker script (see [Linker scripts](https://docs.qualcomm.com/doc/80-N3040-23/topic/linker.html#hu-linker-linker-scripts)). Use the linker to assign the system-specific memory sections to specific memory areas (for more information, see [Subsections](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-subsections-sub)). Note Code and data cannot be stored together in the same system-specific section. ### User-defined sections User-defined sections are defined when a program is to store code or data in a non-standard configuration. They are defined by specifying section names that differ from the [Predefined sections](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-predefined-sections-sub). For example: .section my_strings Copy to clipboard A user-defined section declaration does not specify a section type (code, data, and so on). The assembler automatically determines the section type from the type of objects stored in the section. To make the program more readable, it is common practice to prefix the name of a user- defined section with the section type. For example: .section .rodata.my_strings Copy to clipboard ### Subsections To provide finer control over how items are assigned to memory within a section, the assembler supports subsections for organizing that assignment. For example: .data 1 // subsection 0 .ascii "String assigned to sub-section 1" .data 2 // subsection 1 .ascii "String assigned to sub-section 2" Copy to clipboard The `.text` and `.data` assembler directives accept an argument in the range 0 to 8192. This argument specifies the subsection to which any subsequent declarations are assigned within the current text or data section. The assembler ensures that all items declared in the same subsection are assigned to adjacent addresses in the relevant section. The default subsection is 0. Note Negative subsections are not supported. ## Symbols This section describes how symbols (listed in [Symbols](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-symbols-sub)) are used in the Hexagon assembly language. ### Symbol assignment Symbols are assigned values with the .set directive. For example: .set my_symbol, 78 Copy to clipboard ### Temporary symbols Temporary symbols work like regular symbols in the program source code, but they are typically not saved in the object file. Thus, they are not visible when linking, debugging, or profiling. Temporary symbols are prefixed with `.L`. For example: .L_temp_label Copy to clipboard The `-L` option causes the assembler to save temporary symbols in the object file as local symbols. If the linker is also directed to save local symbols, the resulting temporary symbols can be used in debugging and profiling. Note Temporary symbols differ from ELF local and global symbol types. ### Labels Labels are symbols immediately followed by a colon (`:`). For example: my_label: Copy to clipboard Because labels can cause problems when profiling, do not use them in embedded assembly functions. Instead, use local labels. ### Local labels Local labels can be specified as either symbolic labels or numeric labels. Symbolic local labels are declared and used like regular labels, but they specify a temporary symbol as the label symbol. For example: .L_loc: Copy to clipboard Numeric local labels consist of an integer immediately followed by a colon (`:`). For example: 99: Copy to clipboard Numeric local labels can reuse the same set of numeric label names (`0:, 1:, 2:, ...`) throughout a program. To reference the preceding definition of a numeric label, write `Nb` (where `N` specifies the integer in the label). To reference a subsequent label definition, write `Nf`. For example: 99: nop; jump 99b; // jump to preceding local label 99 99: nop; Copy to clipboard A program can reference only the immediately preceding and following instances of a numeric label symbol. The assembler transforms numeric local labels into unique symbolic local labels (as defined in the example). The generated name includes the numeric local label integer, an ASCII control character (Ctrl-B), and a second integer that indicates the instance of the numeric local label. For example: .L996 Copy to clipboard Note Symbolic local label names can be saved in an object file (see [Temporary symbols](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-temporary-symbols-sub)). ### Dot symbol When used as a symbol, the period character (.) specifies the current address for which the assembler is generating code. For example: my_var: .word . Copy to clipboard The period following the `.word` directive (see [Directives](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives)) specifies the value of the data allocated by `.word`. The value is the memory address of the data. ### Symbol attributes #### Value Symbol values are generally 32-bit numbers. The values can be explicitly assigned in the program code or implicitly assigned by the assembler. - The value of a data symbol is the section-relative offset of the data item. This value is relocatable and is resolved by the linker. - The value of an undefined symbol is 0. This value is resolved by the linker. - The value of a common symbol is the number of bytes to reserve for the symbol in common memory. This value is resolved by the linker. #### Type The symbol type indicates whether a symbol identifies a function or object. It is set with `.type` or `.stabs`. #### Size The symbol size indicates the size (in bytes) of the item identified by the symbol. It is set with `.size` or `.stabs`. #### Scope The symbol scope indicates whether a symbol is local or global. The scope can be made global with `.global`. #### Visibility The symbol visibility indicates whether a symbol is protected, hidden, or internal. - Protected symbols always resolve to symbol definitions in the current component, even if definitions exist in other components that might normally supersede the local definition. - Hidden symbols are protected symbols that are not visible in other components. - Internal symbols are hidden symbols that require extra processing. The visibility is set with `.protected`, `.hidden`, or `.internal`. ### Descriptor The symbol descriptor contains an arbitrary 16-bit value. It is set with `.stabs`. ### Symbol modifiers Symbol modifiers are used to transform the value of the referenced symbol. For example: r0 = add (pc, ##bar@PCREL) Copy to clipboard In this example, the `@PCREL` modifier causes the symbol bar to be evaluated as a PC-relative offset. The following table lists the symbol modifiers and the Hexagon instructions in which they can be used. | Modifier | Description | | --- | --- | | `#HI (symbol)` | Bits [32:16]


`r1.h = #HI (my_symbol)` | | `#LO (symbol)` | Bits [15:0]


`r1.l = #LO (my_symbol)` | | `CONST32 (symbol)` | 32-bit constant


`r12 = CONST32 (#my_symbol)` | | `CONST64 (value)` | 64-bit constant from hexadecimal value


`r13:12 = CONST64 (#0xffff)` | | `symbol@PCREL` | PC-relative offset


`r0 = add (pc, ##my_symbol@PCREL)` | | `symbol@GOT` | Offset of the entry from the global offset table (GOT)


`r2 = memw (r0 + ##my_symbol@GOT)` | | `symbol@GOTREL` | Offset to the location from the GOT


`r4 = my_symbol@GOTREL` | | `symbol@PLT` | Offset to the procedure linkage table (PLT) entry from the current code location


`call my_label@PLT` | | `symbol@GDPLT` | Offset to the PLT entry for the function that returns the address of a thread-local storage (TLS) symbol from the current code location (using the GD method)


`call my_label@GDPLT` | | `symbol@GDGOT` | Offset of the first GOT entry for the TLS\_index structure from the GOT (using the GD method)


`r0 = add (r14, ##my_symbol@GDGOT)` | | `symbol@LDPLT` | Offset to the PLT entry for the function that returns the address of a TLS symbol from the current code location (using the LD method)


`call my_label@LDPLT` | | `symbol@LDGOT` | Offset of the first GOT entry for the TLS\_index structure from the GOT (using the LD method)


`r0 = add (r14, ##my_symbol@LDGOT)` | | `symbol@DTPREL` | Offset to the position from the base of the TLS template (using the LD method)


`r23 = add (r0, ##my_symbol@DTPREL)` | | `symbol@IE` | Address of the GOT entry for the offset into the TLS area (using the IE method)


`r12 = memw (##my_symbol@IE)` | | `symbol@IEGOT` | Offset of the GOT entry for the offset into the TLS area from the GOT (using the IE method)


`r13 = memw (r14 + ##my_symbol@IEGOT)` | | `symbol@TPREL` | Offset to the position from the base of the TLS area (using the LE method)


`r13 = add (r15, ##my_symbol@TPREL)` | Note The symbol modifiers can be used only in specific instructions. For more information, see the *Qualcomm HexagonApplication Binary Interface Specification* (80-N2040-23). ## Directives Assembler directives are used to declare sections, constants, data, and symbols, and to control assembler features such as macros and include files. Directives are prefixed with a period character (`.`) and might be followed by one or more arguments. The assembler recognizes the following directives. [Sections](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-sections-sub) .data [subsection] .section [,"" [,type]] .text [subsection] Copy to clipboard [Symbols](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-symbols-sub) .common , [,align] [,access] .comm , [,align] [,access] .equ , .equiv , .global .globl .lcommon , [,align] [,access] .lcomm , [,align] [,access] .set , .symver , .symver , .symver , Copy to clipboard [Attributes](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-attributes-sub) .hidden [,symbol]... .internal [,symbol]... .protected [,symbol]... .size , .type , Copy to clipboard [Alignment](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-alignment-sub) .align [,abs-expr] [,abs-expr] .balign[w|l] [,abs-expr] [,abs-expr] .falign .p2align[w|l] [,abs-expr] [,abs-expr] .org [,\ ] Copy to clipboard [Data](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-data-sub) .ascii ["string" [,"string"]...] .asciz ["string" [,"string"]...] .byte [expr [,expr]...] .2byte [expr [,expr]...] .4byte [expr [,expr]...] .double [flonum [,flonum]...] .fill , , .float [flonum [,flonum]...] .half [expr [,expr]...] .hword [expr [,expr]...] .int [expr [,expr]...] .long [expr [,expr]...] .quad [bignum [,bignum]...] .short [expr [,expr]...] .single [flonum [,flonum]...] .skip [,fill] .space [,fill] .block [,] .string "" [,"string"]... .word [expr [,expr]...] Copy to clipboard [Conditionals](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-conditionals-sub) .else .elseif .endif .if .ifdef .ifndef .ifnotdef Copy to clipboard [Macros](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-macros-sub) .endm .endr .irp , [,value]... .irpc , .macro .macro ... .purgem Copy to clipboard [Include files](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-include-files-sub) .include "" Copy to clipboard [Debug](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-debug-sub) .file .loc [column] [options] .stabs , , , , .sleb128 [,expr]... .uleb128 [,expr]... Copy to clipboard [Assembler control](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html#hu-directives-assembler-control-sub) .rept [count] Copy to clipboard ### Sections .data [] Copy to clipboard Assign the following data declarations to the specified data subsection. The value must be absolute. The default value is 0. .section [,"" [,]] Copy to clipboard Specify a new section. - `flags` - Specifies one or more section properties: - `a` - Allocatable - `w` - Writable - `x` - Executable The default property depends on the section name; if it is not recognized, the section contains data but has none of the indicated properties. - `type (@progbits, @nobits)` - Specifies whether a section contains data. A section with no data only occupies space. .text [] Copy to clipboard Assign the subsequent Hexagon instructions to the specified code subsection. The value must be absolute. The default value is 0. ### Symbols .common , [,] [,] .comm , [,] [,] Copy to clipboard Declare a common data item with the specified symbol name and data size. - `length` - Specifies the data length (in bytes). - `align` - Specifies the data alignment (in bytes). The alignment value must be an integral power of 2. The default value is the largest power of 2 less than or equal to the length value. - `access` - Specifies the size (in bytes) of the smallest memory access that will be made to the data item. The default value is the align value. .equ , Copy to clipboard Set the symbol value. .equiv , Copy to clipboard Same as `.equ` and `.set`, except that an error is generated if the symbol is already defined. .global .globl Copy to clipboard Declare a symbol as global. .lcommon , [,] [,] .lcomm , [,] [,] Copy to clipboard Declare a local common data item with the specified symbol name and data size. - `length` - Specifies the data length (in bytes). - `align` - Specifies the data alignment (in bytes). The alignment value must be an integral power of 2. The default value is the largest power of 2 less than or equal to the length value. - `access` - Specifies the size (in bytes) of the smallest memory access that will be made to the data item. The default value is the align value. .set , Copy to clipboard Set a symbol to the specified value. If the symbol was previously specified as external, it remains external. If the symbol is global, the value that is stored in the object file is the most recent value stored in the symbol. .symver , .symver , .symver , Copy to clipboard Bind symbols to specific version nodes in a source file. Do this when developing programs that work with shared objects. - `name2` - Specifies the name used to reference the symbol externally. - `nodename` - Specifies the name of a node in the linker script that is used when building a shared library. - Single `@` - This version of the directive behaves differently depending on whether the symbol is defined in the current source file. If it is defined, the symbol is aliased with the name, `name2@nodename`. This alias allows multiple versions of the same function to co-exist in a source file, while still allowing the compiler to be able to distinguish the function references. If the symbol is not defined, all references to it are changed to `name2@nodename`. - Double `@@` - This version of the directive specifies that the symbol must be defined in the source file. It is the same as the single `@` version, except that `name2@@nodename` is also used to resolve references to name2. - Triple `@@@` - This version of the directive specifies that, when the symbol is not defined in the source file, it is treated as `name2@nodename`. Otherwise, it is renamed as `name2@@nodename`. ### Attributes .hidden [,]... Copy to clipboard Set the symbol visibility of the specified symbols to hidden. .internal [,]... Copy to clipboard Set the symbol visibility of the specified symbols to internal. .protected [,]... Copy to clipboard Set the symbol visibility of the specified symbols to protected. .size , Copy to clipboard Set the symbol size to the specified value (in bytes). The value must be absolute, but it can be the result of label arithmetic. .type , Copy to clipboard Set the symbol type. The `type` argument can be one of the following values. - `@function` - Function name - `@gnu_indirect_function` - Indirect function name - `@object` - Data object - `@tls_object` - Thread-local storage data object - `@common` - Common data object - `@notype` - Typeless symbol - `@gnu_unique_object` - Globally unique in process ### Alignment .align [,] [,] Copy to clipboard Pad the location counter in the current subsection until it reaches an integral multiple of the value in the first argument. - The first `abs-expr` argument is the alignment request value (in bytes). It must be an integral multiple of 2 and cannot exceed 0x3ffff. - The second `abs-expr` argument specifies the value to be stored in the padding data. If the argument is omitted, the default value is 0 (or in a text section, the default value is NOPs). - The third `abs-expr` argument specifies the maximum number of bytes to be skipped. If the alignment requires skipping more bytes than the specified value, no alignment is performed. Note The second argument can be omitted by placing two commas between the first and third arguments. .balign[w|l] [,] [,] Copy to clipboard Pad the location counter in the current subsection until it reaches an integral multiple of the value in the first argument. - In `.balignw`, the padding value is a two-byte word value. - In `.balignl`, the padding value is a four-byte longword value. - The first `abs-expr` argument is the alignment request value (in bytes). It must be an integral multiple of 2 and cannot exceed 0x3ffff. - The second `abs-expr` argument specifies the value to be stored in the padding bytes. If the argument is omitted, the default value of each padding byte is 0 (or in a text section, the default value is NOPs). Note The second argument can be omitted by placing two commas between the first and third arguments. - The third `abs-expr` argument specifies the maximum number of bytes to be skipped. If the alignment requires skipping more bytes than the specified value, no alignment is performed. - Subsequent use of `.falign` will override `.balign`. .falign .falign [] Copy to clipboard Align following instruction packets to not cross a 32-byte aligned region. The `packets` argument specifies the number of packets the assembler should align to a cache line boundary. The default value is 1, and the upper limit is 2. Padding is accomplished either by adding NOPs to any empty slots in previous instruction packets or by adding a new instruction packet containing NOPs. The `.falign` directive must be immediately followed by an instruction. It cannot be placed before data directives such as `.word`. This directive is used to reduce the amount of cache activity for time-critical code. The `.falign` directive is short for fetch align. Note A label cannot be assigned to a source line containing an `.falign` directive. .p2align[w|l] [,] [,] Copy to clipboard Pad the location counter in the current subsection until it reaches an integral multiple of 2x, where x is the value of the first argument. - In `.p2alignw`, the padding value is a two-byte word value. - In `.p2alignl`, the padding value is a four-byte longword value. - The first `abs-expr` argument effectively specifies the number of low-order zero bits that the location counter must contain after being advanced. The value must not exceed 17. - The second `abs-expr` argument specifies the value to be stored in the padding bytes. If the argument is omitted, the default value of each padding byte is 0 (or in a text section, the default value is NOPs). - The third `abs-expr` argument specifies the maximum number of bytes to be skipped. If the alignment requires skipping more bytes than the specified value, no alignment is performed. Note The second argument can be omitted by placing two commas between the first and third arguments. .org [,] Copy to clipboard Advance the location counter of the current section and allocate pad data as necessary. - `new-lc` - Must be either absolute or an expression that evaluates to the same section as the current subsection. - `fill` - Specifies the value assigned to the pad data. The default value is 0. ### Data .ascii ["" [,""]...] Copy to clipboard Allocate string literals (with no terminating zero bytes) as character data at consecutive addresses. .asciz ["" [,""]...] Copy to clipboard Allocate string literals (with automatic terminating zero bytes) as character data at consecutive addresses. .byte [ [,]...] Copy to clipboard Allocate expressions as bytes stored at consecutive addresses. .2byte [ [,]...] Copy to clipboard Allocate two-byte data items at consecutive addresses. .4byte [ [,]...] Copy to clipboard Allocate four-byte data items at consecutive addresses. .double [ [,]...] Copy to clipboard Allocate `flonums` as 64-bit floating point numbers stored at consecutive addresses. .fill , [,] [,] Copy to clipboard Allocate fill data at consecutive addresses. - `repeat` - Specify the number of data items to allocate. - `size` - Specify the size (in bytes) of each data item. The default value is 1. - `value` (Optional) - Specify the value assigned to each item. The default value is 0. Note The second argument can be omitted by placing two commas between the first and third arguments. .float [ [,]...] Copy to clipboard Allocate `flonums` as 32-bit floating point numbers stored at consecutive addresses. .half [ [,]...] .hword [ [,]...] Copy to clipboard Allocate expressions as halfwords stored at consecutive addresses. .int [ [,]...] Copy to clipboard Allocate expressions as 32-bit integers stored at consecutive addresses. .long [ [,]...] Copy to clipboard Allocate expressions as 32-bit numbers stored in consecutive addresses. This option accepts zero or more expressions separated by commas. Note This .long option is equivalent to `.int`. .quad [ [,]...] Copy to clipboard Allocate `bignums` as 64-bit integers stored at consecutive addresses. .short [ [,]...] Copy to clipboard Allocate expressions as 16-bit numbers stored at consecutive addresses. .single [ [,]...] Copy to clipboard Allocate `flonums` as 32-bit floating point numbers stored at consecutive addresses. .skip [,] Copy to clipboard Allocate bytes at consecutive addresses, using the specified `fill` value. The default `fill` value is 0. .space [,] .block [,] Copy to clipboard Use `fill` value to allocate bytes at consecutive addresses. The default `fill` value is 0. .string "" [,""]... Copy to clipboard Allocate string literals as character data stored at consecutive byte addresses. Each string is terminated by a zero byte. .word [ [,]...] Copy to clipboard Allocate expressions as 32-bit words stored at consecutive addresses. ### Conditionals .else .elseif .endif Copy to clipboard Conditional assembly directives. .if .ifdef .ifndef .ifnotdef Copy to clipboard Conditional assembly directives. The condition can be the value of an expression (`.if`), whether a symbol is already defined (`.ifdef`), or whether a symbol is not defined (`.ifndef` and `.ifnotdef`). ### Macros .endm Copy to clipboard End of the macro definition. .endr Copy to clipboard End of the macro definition. Mark the end of a sequence of source lines processed by the `.rept` directive. .irp , []... Copy to clipboard Generate a macro-like sequence of similar statements, assigning a different value to the symbol parameter in each statement template. The statement template is delimited by the `.irp` and `.endr` directives, with the symbol appearing in the template as a parameter prefixed by the backslash character (`\`). For example: > > > .irp ,1,2,3 > move x\,sp@- > .endr > Copy to clipboard This declaration generates the following assembly statements: > > > move x1,sp@- > move x2,sp@- > move x3,sp@- > Copy to clipboard .irpc , Copy to clipboard Generate a macro-like sequence of similar statements, assigning a different character from string to the symbol parameter in each statement template. The statement template is delimited by the `.irpc` and `.endr` directives, with the symbol appearing in the template as a parameter prefixed by the backslash character (`\`). For example: > > > .irpc ,1,2,3 > move x\,sp@- > .endr > Copy to clipboard This declaration generates the following assembly statements: > > > move x1,sp@- > move x2,sp@- > move x3,sp@- > Copy to clipboard .macro .macro ... Copy to clipboard Declare a macro. Macro arguments in the macro declaration must be separated by commas or spaces. The macro definition is delimited by the .macro and .endm directives, with the macro parameters appearing in the macro definition as the macro argument name prefixed by the backslash character (`\`). Declare the macro arguments with the following options: > > > arg= > Copy to clipboard > > > Default value if the argument is not specified in the macro call. > > > arg:req > Copy to clipboard > > > The argument must always be assigned a non-blank value in macro calls. > > > arg:vararg > Copy to clipboard > > > The argument assigned all remaining arguments in the macro call. In macro calls, specify the arguments either by name (`add p1=17, p2=9`) or by order in the argument list (`add 17,9`). .purgem Copy to clipboard Delete the macro definition for the specified macro. Once deleted, the name can be used for a new macro declaration. ### Include files .include "" Copy to clipboard Include the contents of the specified file into the program. ### Debug .file Copy to clipboard Assign file names to the file name table .debug\_line. - `fileno` - Specifies an index into the file name table. The index value must be unique with respect to any other instances of the file directive in the program. - `filename` - A C string literal. This directive is used when generating DWARF debug information. .loc [] [...] Copy to clipboard Add rows to the .debug\_line line number matrix. - `fileno` - Specifies an entry index in the file name table. - `lineno` and `column` - Specify a file position. - `options` - Specifies one or more instances of the following values: - `basic_block` - `prologue_end` - `epilogue_end` - `is_stmt ` - `isa ` .stabs , , , , Copy to clipboard Define symbols that are used by symbolic debuggers. The directive arguments are used to set the following symbol attributes: `name`, `value`, `type`, `descriptor`, and `other`. These symbols are used for debugging; they cannot be referenced in the assembly source code. .sleb128 [,]... Copy to clipboard Allocate the specified expressions as sleb128-format numbers stored at consecutive addresses. `sleb128` is an acronym for *signed little-endian base 128*. This format is used when generating DWARF debug information. .uleb128 [,]... Copy to clipboard Allocate expressions as uleb128-format numbers stored at consecutive addresses. `uleb128` is an acronym for *unsigned little-endian base 128*. This format is used when generating DWARF debug information. ### Assembler control .rept [] Copy to clipboard Generate a macro-like sequence of statements, where `count` indicates the number of times the statement sequence is to be repeated in the code. The default value is 0. The statement sequence is delimited by the `.rept` and `.endr` directives. ## Packet splitting guidance for Small Cores Hexagon Small Cores have fewer slots available for packetized instructions. Because many instruction packets in hand-written assembly code are invalid for the Small Core, much of the existing assembly source code is unusable on Small Cores without significant redesign. An invalid packet might have too many instructions, or the instructions might not be placed in the correct slots. Note For an explanation of available slots, see the “Resource constraints” section in the *Qualcomm Hexagon Programmer’s Reference Manual*. Following are steps you can take to ease the porting of assembly source code, written for V5 through V66, to successfully assemble code for V67t (Small Core). These examples are applicable to any Hexagon Small Core, and they are designed to be used with Hexagon 8.3 or later tools. ### No packet-splitting option Using `-mv71t` without a packet-split option, the assembler: - Uses the default `-mpacket-split-hw` option - Does not split any packets - Displays no errors or warnings about `native-small-core-invalid` packets Using this switch tells the assembler to disregard `native-small-core-invalid` packets, and that any packet splitting will be done by the Hexagon processor at runtime. ### Hardware split Using `-mv71t -mno-packet-split-hw` on the hexagon-clang command line tells the assembler: - To report all packets that are not compatible with Small Core - To not attempt to split any packets This approach is appropriate for Small Core targets that are not expected to have a packet-splitting function in the hardware. **Example** hexagon-clang -mv71t -O2 -G0 -g -mno-packet-split-hw -c nosplit.S -o nosplit.o nosplit.S:23:1: error: invalid instruction packet: slot error } ^ nosplit.S:23:1: error: invalid instruction packet: out of slots } Copy to clipboard ### Software split Using `-mv71t -mpacket-split-sw` on the hexagon-clang command line tells the assembler: - To split all the invalid packets that it can - To flag as errors those packets it cannot split **Example** hexagon-clang -mv71t -O2 -G0 -g -mpacket-split-sw -c nosplit.S -o nosplit.o nosplit.S:23:1: error: failed to split this packet } Copy to clipboard ### Atomicity semantics However you choose to alter the packets in existing Hexagon assembly source code to comply with Small Core constraints, the resulting packets will probably operate differently from the original code at the atomic level. For example, if a single packet reads a register and clears a bit in a memory-mapped input/output register, splitting these operations into two packets now allows for an interrupt to arrive between these two packets. The revised (Small Core) code must account for these new possibilities. ### Instruction serialization To preserve the functionality of packets being split, the assembler internally creates a serialized representation of the instructions in the packet. This representation is of the dependencies among the parts of instructions that would execute serially on the Hexagon processor. The rules for these dependencies are described in the *Qualcomm Hexagon Programmer’s Reference Manual*. ### Memory ordering For maximum fidelity, the assembler’s packet splitter orders multiple memory operations such that their effects match the behavior of the target Hexagon processor. If you know in advance that multiple memory operations cannot have an alias or that their effects do not require this ordering, you can disable this feature: - Globally with the `-mpacket-mem-no-order` flag - Locally to a packet with the `:mem_no_order` attribute By disabling this feature, the assembler’s packet splitter will not map these dependencies and will be less likely to encounter cyclical dependencies. ### Examples The `nosplit.S` source file includes one packet with four instructions: { r0=memw(r6) r3=r5 r5=r7 memw(r7)=r0 } Copy to clipboard When the packet splitter considers this packet according to the serialization rules of the target architecture, it finds an unresolvable dependency cycle among the instructions. This packet cannot be split by the assembler. **Assemble nosplit.S with default arguments and then with -mpacket-split-sw** In this example, the assembler with default arguments throws no warning or error on this packet when building for `-mv71t`. But using `-mpacket-split-sw` throws an error on this packet: hexagon-clang -mv71t -O2 -G0 -g -c nosplit.S -o nosplit_test.o No error or warning about the four-instruction packet ------------------------------------ hexagon-clang -mv71t -O2 -G0 -g -mpacket-split-sw -c nosplit.S -o nosplit.o nosplit.S:23:1: error: failed to split this packet } ^ Copy to clipboard **Write new assembly source code to manage packet splitting inherently** To design the source file so it builds for standard or Small Core Hexagon processors without using the `-mpacket-split-sw switch`, add `#if __HEXAGON_PHYSICAL_SLOTS__ == 3 } { #endif` conditionals where you want packets to be split. This method makes it clear how packets must be split, focusing attention on the effects of these splits. `__HEXAGON_PHYSICAL_SLOTS__` is a default hexagon-clang macro that is automatically set to the number of slots available in the designated processor. Select it by using the `-mv_` switch: - For `-mv71, __HEXAGON_PHYSICAL_SLOTS__ = 4` - For `-mv71t, __HEXAGON_PH YSICAL_SLOTS__ = 3` #### Packet comparison This example shows a comparison of packets that the assembler can split with `-mpacket-split-sw`, and packets that are manually split by inserting preprocessor directives. split_soft.S // packet splitting for Small Core .text .global small_split .type small_split, @function small_split: // load and store in the same packet load_store_asm: { r6=r0 r1=memw(r0) r2=r7 memw(r4)=r3 } // load and store in the same packet load_store_man: { r6=r0 r1=memw(r0) #if __HEXAGON_PHYSICAL_SLOTS__ == 3 } { #endif r2=r7 memw(r4)=r3 } // hw loop loop_split_asm: { loop0(base_a,#7) r9:8=memd(r24+#8) r15:14=memd(r24++#16) } base_a: { memd(r2++#16)=r15:14 r1:0=memd(r24++#16) }:endloop0 // hw loop loop_split_man: { loop0(base_m,#7) r9:8=memd(r24+#8) #if __HEXAGON_PHYSICAL_SLOTS__ == 3 } { #endif r15:14=memd(r24++#16) } base_m: { memd(r2++#16)=r15:14 #if __HEXAGON_PHYSICAL_SLOTS__ == 3 } { #endif r1:0=memd(r24++#16) }:endloop0 // two instructions in execute slot exec_split_asm: { usr = r28 // slot X only r5 ^= lsr(r1,#31) // slot X only r28 = r5 } exec_split_man: { usr = r28 // slot X only #if __HEXAGON_PHYSICAL_SLOTS__ == 3 } { #endif r5 ^= lsr(r1,#31) // slot X only r28 = r5 } .size small_split, .-small_split Copy to clipboard Last Published: Oct 06, 2026 [Previous Topic System requirements](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/utilities-ug-overview.md) [Next Topic Linker](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/linker.md) Source: [https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html](https://docs.qualcomm.com/doc/80-N3040-23/topic/assembler.html)