mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
35 lines
845 B
Zig
35 lines
845 B
Zig
pub fn main() noreturn {
|
|
const msg = "hello world\n";
|
|
_ = syscall3(SYS_write, STDOUT_FILENO, @intFromPtr(msg), msg.len);
|
|
_ = syscall1(SYS_exit, 0);
|
|
unreachable;
|
|
}
|
|
|
|
pub const SYS_write = 1;
|
|
pub const SYS_exit = 60;
|
|
|
|
pub const STDOUT_FILENO = 1;
|
|
|
|
pub fn syscall1(number: usize, arg1: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [number] "{rax}" (number),
|
|
[arg1] "{rdi}" (arg1),
|
|
: "rcx", "r11"
|
|
);
|
|
}
|
|
|
|
pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
|
return asm volatile ("syscall"
|
|
: [ret] "={rax}" (-> usize),
|
|
: [number] "{rax}" (number),
|
|
[arg1] "{rdi}" (arg1),
|
|
[arg2] "{rsi}" (arg2),
|
|
[arg3] "{rdx}" (arg3),
|
|
: "rcx", "r11"
|
|
);
|
|
}
|
|
|
|
// exe=succeed
|
|
// target=x86_64-linux
|