Created
November 29, 2024 04:50
-
-
Save derekthecool/a24dcd30a70b413d8657c488c8aefb22 to your computer and use it in GitHub Desktop.
Clash of code assembly
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
#!/bin/bash | |
# Use a here document to write assembly code into clash.s | |
cat <<EOF > clash.s | |
.global _start | |
.section .data | |
msg: | |
.asciz "Hello, World!\n" | |
.section .text | |
_start: | |
mov \$1, %rax # sys_write (1) | |
mov \$1, %rdi # File descriptor 1 (stdout) | |
lea msg(%rip), %rsi # Load address of msg into %rsi | |
mov \$14, %rdx # Length of the message (14 bytes including newline) | |
syscall # Invoke syscall | |
mov \$60, %rax # sys_exit (60) | |
xor %rdi, %rdi # Return code 0 | |
syscall # Invoke syscall to exit | |
EOF | |
# Assemble the code into object file | |
as --64 clash.s -o clash.o | |
# Link the object file to create the executable | |
ld clash.o -o program | |
# Run the program | |
./program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment