Created
December 27, 2024 20:01
-
-
Save renatoathaydes/950cd1e0d032bc65a693bcc469cd3afc to your computer and use it in GitHub Desktop.
D Hello World in Assembly without libc
This file contains 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
/** | |
Inspired by https://4zm.org/2024/12/25/a-simple-elf.html | |
Found MacOS syscall code by luck on https://stackoverflow.com/questions/47834513/64-bit-syscall-documentation-for-macos-assembly | |
ASM register explanations: https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm | |
Compile this with: "dmd -betterC -ofhello hello.d" | |
**/ | |
extern(C) int main() | |
{ | |
auto hip = "hello D\n".ptr; | |
size_t len = 8; | |
// write(1, message, length) | |
asm { | |
mov RDX, len; // Buffer length | |
mov RSI, hip; // Message buffer | |
mov EDI, 1; // Stdout file descriptor (0x01) | |
mov RAX, 0x2000004; // write syscall number (0x01 on Linux) | |
syscall; // Make the syscall | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment