You copied the Doc URL to your clipboard.

Arm Compiler armclang Reference Guide : __semihost intrinsic

__semihost intrinsic

This intrinsic inserts an SVC or BKPT instruction into the instruction stream generated by the compiler. It enables you to make semihosting calls from C or C++ that are independent of the target architecture.

To use this intrinsic, your source file must contain #include <arm_compat.h>. This is only available for targets in AArch32 state.


int __semihost(int val, const void *ptr)


Is the request code for the semihosting request.
Is a pointer to an argument/result block.

Return value

The results of semihosting calls are passed either as an explicit return value or as a pointer to a data block.


Use this intrinsic from C or C++ to generate the appropriate semihosting call for your target and instruction set:

SVC 0x123456
In A32 state, excluding M-profile architectures.
In T32 state, excluding M-profile architectures. This behavior is not guaranteed on all debug targets from Arm or from third parties.
HLT 0xF000
In A32 state, excluding M-profile architectures.
HLT 0x3C
In T32 state, excluding M-profile architectures.
For M-profile architectures (T32 only).


For Arm® processors that are not Cortex®‑M profile, semihosting is implemented using the SVC or HLT instruction. For Cortex‑M profile processors, semihosting is implemented using the BKPT instruction.

To use HLT-based semihosting, you must define the pre-processor macro __USE_HLT_SEMIHOSTING before #include <arm_compat.h>. By default, Arm Compiler emits SVC instructions rather than HLT instructions for semihosting calls. If you define this macro, __USE_HLT_SEMIHOSTING, then Arm Compiler emits HLT instructions rather than SVC instructions for semihosting calls.

The presence of this macro, __USE_HLT_SEMIHOSTING, does not affect the M-profile architectures that still use BKPT for semihosting.


char buffer[100];
void foo(void)
    __semihost(0x01, (const void *)buffer);

Compiling this code with the option -mthumb shows the generated SVC instruction:

    MOVW     r0, :lower16:buffer
    MOVT     r0, :upper16:buffer
    SVC      #0xab

    .zero    100
    .size    buffer, 100