Assembly online compiler
Write Assembly (NASM 3) code below and run it free, with input, in a sandbox on our servers. No sign-in, no ads. The same compiler is an API and an embeddable editor, for running Assembly in your own app, course or docs.
Também em portuguêsTambién en español
Run Assembly from your own app, bot or course. One API call returns the output, errors, exit code and run time. Free up to 100,000 runs a month, commercial use included, no card.
Checking a solution against several inputs? The Assembly online compiler with test cases runs them all at once and marks each one passed or failed.
x86-64 assembly examples: system calls and printf
Hello world with Linux system calls only: _start is the entry point, system call 1 writes and 60 exits.
section .data
msg db "Hello from NASM!", 10
len equ $ - msg
section .text
global _start
_start:
mov rax, 1 ; system call 1: write
mov rdi, 1 ; to stdout
lea rsi, [rel msg]
mov rdx, len
syscall
mov rax, 60 ; system call 60: exit
xor rdi, rdi ; with status 0
syscallReading a number and looping: with a global main, the program is linked with the C library, so it can call scanf and printf. Keep the stack 16-byte aligned before each call.
extern scanf
extern printf
section .data
fmt_in db "%ld", 0
fmt_out db "Sum of 1 to %ld is %ld", 10, 0
section .bss
n resq 1
section .text
global main
main:
sub rsp, 8 ; keep the stack 16-byte aligned for calls
lea rdi, [rel fmt_in]
lea rsi, [rel n]
xor eax, eax
call scanf
mov rcx, [rel n] ; counter, from n down to 1
xor edx, edx ; running sum
test rcx, rcx
jle .done
.loop:
add rdx, rcx
dec rcx
jnz .loop
.done:
lea rdi, [rel fmt_out] ; printf(fmt_out, n, sum)
mov rsi, [rel n]
xor eax, eax
call printf
add rsp, 8
xor eax, eax
retWith 100 in the Input tab it prints Sum of 1 to 100 is 5050.
What runs your code
| Version | Assembly NASM 3 |
|---|---|
| Compiled with | nasm -f elf64 code.asm -o code.o && ld code.o -o code.out |
| Run with | ./code.out |
| Limits | 30 seconds, 512 MB of memory (up to 2 GB through the API on Pro and above), 2 CPUs, 64 KB of output per stream, no network |
| Typical run | 0.68 s, and 0.84 s for the slowest 1 in 20 (how we measured) |
Good to know
- Assembles 64-bit x86-64 Linux code with NASM 3 (
nasm -f elf64). - A program with a global
mainis linked with the C library, so it can callprintfandscanf. One with_startis linked on its own and uses system calls. - Use
syscallwith the 64-bit call numbers (1 is write, 60 is exit). 32-bitint 0x80calls crash with exit code 139.
Assembly compiler API
To run Assembly from your own app, send the code and its input to the sync endpoint with an API key, and the output comes back in the response. It's free up to 100,000 runs a month, with no credit card: get a free API key. The API docs cover the async endpoint with callbacks and every response field.
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"compiler": "nasm-3",
"code": "extern scanf\nextern printf\n\nsection .data\nfmt_in db \"%63s\", 0\nfmt_out db \"Hello, %s!\", 10, 0\n\nsection .bss\nname resb 64\n\nsection .text\nglobal main\nmain:\n sub rsp, 8\n lea rdi, [rel fmt_in]\n lea rsi, [rel name]\n xor eax, eax\n call scanf\n lea rdi, [rel fmt_out]\n lea rsi, [rel name]\n xor eax, eax\n call printf\n add rsp, 8\n xor eax, eax\n ret",
"input": "Ada"
}'The response has output ("Hello, Ada!\n" here), error, exit_code, time and memory.
Embed a Assembly compiler in your website
The editor above is the embeddable widget. Add the script and a div with your widget key, and your readers can edit and run the code without an account:
<script src="https://onlinecompiler.io/widget.js"></script>
<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="nasm-3">
<script type="text/plain">
extern scanf
extern printf
section .data
fmt_in db "%63s", 0
fmt_out db "Hello, %s!", 10, 0
section .bss
name resb 64
section .text
global main
main:
sub rsp, 8
lea rdi, [rel fmt_in]
lea rsi, [rel name]
xor eax, eax
call scanf
lea rdi, [rel fmt_out]
lea rsi, [rel name]
xor eax, eax
call printf
add rsp, 8
xor eax, eax
ret
</script>
<a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>On a platform that takes an iframe but not a script, such as many course sites, use the iframe embed. For Docusaurus, MkDocs, Sphinx and Mintlify, see runnable code examples in docs.
Other languages
Python, C, C++, Java, C#, F#, Go, Rust, PHP, Ruby, Haskell, TypeScript, JavaScript, SQL, DuckDB, Bash, Fortran, Visual Basic, Kotlin, R, Swift, COBOL, Perl, Julia, Pascal, Octave, Lua, OCaml, Common Lisp, Erlang, Elixir, Prolog, D, FreeBASIC, Dart, Clojure, Groovy, Scala, Zig, Nim, Crystal, Ada, PowerShell, Racket, Objective-C.
Frequently asked questions
Is this Assembly online compiler free?
Yes. Running Assembly on this page needs no account and shows no ads. To run Assembly from your own app or site, the API and the widget are free up to 100,000 runs a month, commercial use included.
Is there a Assembly compiler API?
Yes. POST the code, the compiler id nasm-3 and any input to https://api.onlinecompiler.io/api/run-code-sync/ with an API key, and the response holds the output, errors, exit code, run time and memory. It's free up to 100,000 runs a month, and the same key works for the other 45 languages.
Can my Assembly program read input?
Yes. Type it in the Input tab before you run, and the program reads it from standard input. The whole input is sent when you press Run, so a program can't ask for more while it runs.
Can I use Assembly libraries?
The C standard library, for programs that define main. There are no other libraries or include files, and programs have no network access.
Can I run 8086 or DOS assembly with int 21h?
No. Programs are 64-bit x86-64 Linux code: org 100h is refused, and int 21h stops the program with exit code 139. Use Linux system calls (1 is write, 60 is exit), or call printf and scanf from main, as in the examples above.
Does it accept MASM or TASM code?
No, NASM syntax only. MASM and TASM directives such as .model, .stack and proc don't assemble; NASM reports "instruction expected".
Can I share or save my code?
Yes. Share gives you a link that anyone can open and run, lasts 90 days and needs no account. Save keeps the code in your OnlineCompiler.io account until you delete it. When you are signed in, each run you make on this page is also kept in your account's run history.
How long can a program run?
Up to 30 seconds, with 512 MB of memory (up to 2 GB through the API on Pro and above) and 2 CPUs. A program still running at 30 seconds is stopped with exit code 124, and output over 64 KB per stream is cut.
Where does my code run?
On our servers, in a fresh gVisor sandbox with no network access that is deleted when the run ends. Each run is kept in execution history with its output; the security page says what is stored.