Created
April 26, 2022 16:09
-
-
Save tylerhjones/9a01b2e7aee67c0de67cb4ed87ef438d to your computer and use it in GitHub Desktop.
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
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