Can I add my own assembly file/instructions to a godbolt project?

Just like the title suggests. Say, I want to do this with a Godbolt project:


#include <iostream>

extern "C" int test_111();

int main()
    int r = test_111();
    std::cout << "result=" << r << std::endl;
    return 0;

and then in asm1.asm:


test_111 PROC

    ; 64-bit assembly
    xor eax, eax
    inc rax


test_111 ENDP


Trying it under "x86-64 clang" (any version).

But I can't seem to figure out how to do this. Any suggestions?

PS. The goal is to inject my own assembly instructions into the output.


After a suggestion in the comments, I tried the asm volatile key words, but it simply adds whatever gibberish I put in there into the assembly output:

enter image description here


  • Using the Tree mode, you can set up a CMake project with multiple files, including asm:

    Godbolt Link

    To make it work, I had to enable nasm support in the CMakeLists.txt file and manually set the path to the assembler

    set(CMAKE_ASM_NASM_COMPILER /opt/compiler-explorer/nasm-2.14.02/bin/nasm)
    set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")