Inline assembly support

Open XL C/C++ for z/OS® provides the following enhancements to the inline assembly support: HLASM macros, self-defining terms, and hard register operands.
Note: Inline assembly statements must be in HLASM format.

HLASM macros

Open XL C/C++ for z/OS supports HLASM macros. You can use -mzos-asmlib to specify the assembler macro libraries to be used with assembling the inline assembly statement.

For example, to compile the following code,
int main() {
    asm(" SYSSTATE ARCHLVL=2\n"
    " WTO 'This is a test',DESC=9,ROUTCDE=2 \\n");
    return 0;
}
Run this command:
ibm-clang -mzos-asmlib="//'SYS1.MACLIB'" main.c

A warning message is issued, saying that -mzos-asm-implicit-clobber-reg=r0,r1,r14,r15 is enabled by default because -masmlib=SYS1.MACLIB is specified.

You can adjust this clobber list with -mzos-asm-implicit-clobber-reg or disable the warning message with -mno-zos-asm-implicit-clobber-reg. For example, run the following command to clobber different registers:
ibm-clang -mzos-asmlib="//'SYS1.MACLIB'" -mzos-asm-implicit-clobber-reg=r0,r1 main.c

Self-defining terms

Self-defining terms are supported and can be included in inline assembly statements directly. For example,
asm(" dc x'b93c008a'" :::);

Hard register operands

In Open XL C/C++ for z/OS, you can specify specific hardware registers in inline assembly constraints by using curly braces {}, which instructs the compiler to load the variable into the associated register for the inline assembly instructions. For example:
void func() {
    int x = func1();
    int y = func2();

    asm(" LR %0,%1\n": "={r0}"(x) : "{r1}"(y));
}

Hard register operands apply to the specific inline assembly statement only.

Related information