Skip to content

Instantly share code, notes, and snippets.

@tylerhjones
Created April 26, 2022 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerhjones/9a01b2e7aee67c0de67cb4ed87ef438d to your computer and use it in GitHub Desktop.
Save tylerhjones/9a01b2e7aee67c0de67cb4ed87ef438d to your computer and use it in GitHub Desktop.
use std::arch::asm;
fn sys_print(msg: &str) {
// mac only
unsafe {
asm!(
"mov rdx,{0}", // length of msg
"mov rsi,{1}", // msg
"mov rdi,1", // 1 = stdout
"mov rax,0x2000004", // 4 = sys_write ? you have to add 0x20000000 to the syscall number on mac ... why??
"syscall", // yield to kernel
in(reg) msg.len(),
in(reg) msg.as_ptr(),
);
}
}
fn main() {
sys_print("Water your plants, but not too much.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment