Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
assembly source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
AArch64 binutils 2.28
AArch64 binutils 2.31.1
AArch64 binutils 2.33.1
AArch64 binutils 2.35.1
AArch64 binutils 2.38
AArch64 binutils 2.45
ARM binutils 2.25
ARM binutils 2.28
ARM binutils 2.31.1
ARM gcc 10.2 (linux)
ARM gcc 13.2 (linux)
ARM gcc 15.1 (linux)
ARM gcc 9.3 (linux)
ARMhf binutils 2.28
BeebAsm 1.09
NASM 2.12.02
NASM 2.13.02
NASM 2.13.03
NASM 2.14.02
NASM 2.16.01
RISC-V binutils 2.31.1
RISC-V binutils 2.31.1
RISC-V binutils 2.35.1
RISC-V binutils 2.35.1
RISC-V binutils 2.37.0
RISC-V binutils 2.37.0
RISC-V binutils 2.38.0
RISC-V binutils 2.38.0
RISC-V binutils 2.42.0
RISC-V binutils 2.42.0
RISC-V binutils 2.45.0
RISC-V binutils 2.45.0
x86-64 binutils (trunk)
x86-64 binutils 2.27
x86-64 binutils 2.28
x86-64 binutils 2.29.1
x86-64 binutils 2.34
x86-64 binutils 2.36.1
x86-64 binutils 2.38
x86-64 binutils 2.42
x86-64 binutils 2.45
x86-64 clang (assertions trunk)
x86-64 clang (trunk)
x86-64 clang 10.0.0
x86-64 clang 10.0.1
x86-64 clang 11.0.0
x86-64 clang 11.0.1
x86-64 clang 12.0.0
x86-64 clang 12.0.1
x86-64 clang 13.0.0
x86-64 clang 14.0.0
x86-64 clang 15.0.0
x86-64 clang 16.0.0
x86-64 clang 17.0.1
x86-64 clang 18.1.0
x86-64 clang 19.1.0
x86-64 clang 20.1.0
x86-64 clang 21.1.0
x86-64 clang 3.0.0
x86-64 clang 3.1
x86-64 clang 3.2
x86-64 clang 3.3
x86-64 clang 3.4.1
x86-64 clang 3.5
x86-64 clang 3.5.1
x86-64 clang 3.5.2
x86-64 clang 3.6
x86-64 clang 3.7
x86-64 clang 3.7.1
x86-64 clang 3.8
x86-64 clang 3.8.1
x86-64 clang 3.9.0
x86-64 clang 3.9.1
x86-64 clang 4.0.0
x86-64 clang 4.0.1
x86-64 clang 5.0.0
x86-64 clang 6.0.0
x86-64 clang 7.0.0
x86-64 clang 8.0.0
x86-64 clang 9.0.0
Options
Source code
.intel_syntax noprefix .section .data stars_x: .space 800 # x coordinates (100 stars * 8 bytes) stars_y: .space 800 # y coordinates stars_z: .space 800 # z coordinates screen: .space 500000 # Very large screen buffer for any terminal size seed: .quad 12345 # random seed term_rows: .quad 24 # Terminal rows (will be detected) term_cols: .quad 80 # Terminal cols (will be detected) clear_seq: .ascii "\033[2J\033[H" clear_len = . - clear_seq newline: .ascii "\n" .section .text .global _start _start: # Get terminal size using ioctl call get_terminal_size # Initialize stars call init_stars main_loop: # Clear screen mov rax, 1 # sys_write mov rdi, 1 # stdout mov rsi, offset clear_seq mov rdx, clear_len syscall # Clear screen buffer mov rdi, offset screen mov rcx, [rip + term_rows] mov rax, [rip + term_cols] imul rcx, rax mov al, 32 # space character rep stosb # Update and draw stars call update_stars call draw_stars # Display screen mov rax, 1 # sys_write mov rdi, 1 # stdout mov rsi, offset screen mov rdx, [rip + term_rows] mov rcx, [rip + term_cols] imul rdx, rcx syscall # Small delay mov rax, 35 # sys_nanosleep mov rdi, offset delay_spec mov rsi, 0 syscall jmp main_loop init_stars: mov r8, 0 # star index init_loop: cmp r8, 100 jge init_done # Random x (-cols/2 to cols/2) call random mov rbx, [rip + term_cols] and rax, 0x3FF # Use more bits for wider range xor rdx, rdx div rbx # rax % term_cols mov rax, rdx shr rbx, 1 sub rax, rbx mov [stars_x + r8*8], rax # Random y (-rows/2 to rows/2) call random mov rbx, [rip + term_rows] and rax, 0x1FF # Use more bits for taller terminals xor rdx, rdx div rbx # rax % term_rows mov rax, rdx shr rbx, 1 sub rax, rbx mov [stars_y + r8*8], rax # Random z (1 to 100) call random and rax, 0x7F add rax, 1 mov [stars_z + r8*8], rax inc r8 jmp init_loop init_done: ret update_stars: mov r8, 0 # star index update_loop: cmp r8, 100 jge update_done # Move star closer (decrease z) mov rax, [stars_z + r8*8] sub rax, 2 # If z <= 0, reset star cmp rax, 0 jle reset_star mov [stars_z + r8*8], rax jmp next_star reset_star: # New random position call random mov rbx, [rip + term_cols] and rax, 0x3FF xor rdx, rdx div rbx mov rax, rdx shr rbx, 1 sub rax, rbx mov [stars_x + r8*8], rax call random mov rbx, [rip + term_rows] and rax, 0x1FF xor rdx, rdx div rbx mov rax, rdx shr rbx, 1 sub rax, rbx mov [stars_y + r8*8], rax mov rax, 100 mov [stars_z + r8*8], rax next_star: inc r8 jmp update_loop update_done: ret draw_stars: mov r8, 0 # star index draw_loop: cmp r8, 100 jge draw_done # Project 3D to 2D using terminal dimensions mov rax, [stars_x + r8*8] mov rbx, [rip + term_cols] shr rbx, 1 # cols/2 imul rax, rbx mov rbx, [stars_z + r8*8] cmp rbx, 0 je next_draw cqo idiv rbx mov rbx, [rip + term_cols] shr rbx, 1 add rax, rbx # + cols/2 # Check X bounds cmp rax, 0 jl next_draw mov rbx, [rip + term_cols] dec rbx cmp rax, rbx jg next_draw mov rcx, rax # screen_x mov rax, [stars_y + r8*8] mov rbx, [rip + term_rows] shr rbx, 1 # rows/2 imul rax, rbx mov rbx, [stars_z + r8*8] cqo idiv rbx mov rbx, [rip + term_rows] shr rbx, 1 add rax, rbx # + rows/2 # Check Y bounds cmp rax, 0 jl next_draw mov rbx, [rip + term_rows] dec rbx cmp rax, rbx jg next_draw mov rdx, rax # screen_y # Calculate screen position mov rax, rdx mov rbx, [rip + term_cols] imul rax, rbx add rax, rcx # Draw star character based on distance mov rbx, [stars_z + r8*8] cmp rbx, 20 jl bright_star cmp rbx, 50 jl medium_star mov byte ptr [screen + rax], 46 # '.' jmp next_draw medium_star: mov byte ptr [screen + rax], 42 # '*' jmp next_draw bright_star: mov byte ptr [screen + rax], 35 # '#' next_draw: inc r8 jmp draw_loop draw_done: ret get_terminal_size: # Use ioctl TIOCGWINSZ to get terminal size sub rsp, 16 # Space for winsize struct mov rax, 16 # sys_ioctl mov rdi, 0 # stdin mov rsi, 0x5413 # TIOCGWINSZ mov rdx, rsp # winsize struct syscall # Extract rows and cols from struct movzx eax, word ptr [rsp] # ws_row (short) mov [rip + term_rows], rax movzx eax, word ptr [rsp + 2] # ws_col (short) mov [rip + term_cols], rax add rsp, 16 ret random: mov rax, [rip + seed] mov rbx, 1103515245 imul rax, rbx add rax, 12345 mov [rip + seed], rax ret .section .data delay_spec: .quad 0, 50000000 # 50ms delay .section .text exit: mov rax, 60 # sys_exit mov rdi, 0 syscall
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree