Skip to content

Instantly share code, notes, and snippets.

@ZhangHanDong
Forked from kekeimiku/rust-helloworld.rs
Created April 24, 2021 09:56
Show Gist options
  • Save ZhangHanDong/19567d2a8a10f93cc948d79ab0e5691c to your computer and use it in GitHub Desktop.
Save ZhangHanDong/19567d2a8a10f93cc948d79ab0e5691c to your computer and use it in GitHub Desktop.
rust helloworld
#![no_std]
#![no_main]
#![feature(asm)]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
fn _start() -> ! {
let h: &str = "Hello, World!";
unsafe {
asm!(
"syscall",
in("rax") 1,
in("rdi") 1,
in("rsi") h.as_ptr() as u64,
in("rdx") h.len() as u64,
out("rcx") _,
out("r11") _,
lateout("rax") _,
);
//exit
asm!(
"syscall",
in("rax") 60,
in("rdi") 0,
out("rcx") _,
out("r11") _,
lateout("rax") _,
);
};
loop {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment