Skip to content

Instantly share code, notes, and snippets.

@nokotan
Created March 13, 2021 15:58
Show Gist options
  • Save nokotan/78ecf012340908daa0a6ce47642718c9 to your computer and use it in GitHub Desktop.
Save nokotan/78ecf012340908daa0a6ce47642718c9 to your computer and use it in GitHub Desktop.
inline WebAssembly in emscripten
#include <cstdint>
#include <iostream>
int32_t add(int32_t n) {
int32_t sum;
__asm (
"local.get %1\n"
"i32.const 1\n"
"i32.add\n"
"local.set %0"
: "=r"(sum)
: "r"(n)
);
return sum;
}
int main() {
int32_t a;
std::cin >> a;
std::cout << add(a) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment