-
-
Save michidk/0addb0fdcb7de291033027e742f44522 to your computer and use it in GitHub Desktop.
Rust 1.98.1 naked assembly Hello World: 209 bytes with default GNU ld script, 153 with minimal.ld; 1616 unoptimized with required static entry-point flags; exits 0 after returned write errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![no_std] | |
| #![no_main] | |
| use core::{arch::naked_asm, panic::PanicInfo}; | |
| static MSG: [u8; 14] = *b"Hello, World!\n"; | |
| #[unsafe(naked)] | |
| #[unsafe(no_mangle)] | |
| extern "C" fn _start() -> ! { | |
| naked_asm!( | |
| "mov al, 1", | |
| "mov edi, eax", | |
| "mov esi, offset {msg}", | |
| "mov dl, 14", | |
| "syscall", | |
| "xchg eax, ebx", | |
| "xchg eax, edi", | |
| "mov al, 60", | |
| "syscall", | |
| msg = sym MSG, | |
| ); | |
| } | |
| #[panic_handler] | |
| fn panic(_: &PanicInfo<'_>) -> ! { loop {} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment