Skip to content

Instantly share code, notes, and snippets.

@TheFlash2k
Created December 31, 2023 07:35
Show Gist options
  • Save TheFlash2k/158ba694b9438c1e20866ed62e523cc5 to your computer and use it in GitHub Desktop.
Save TheFlash2k/158ba694b9438c1e20866ed62e523cc5 to your computer and use it in GitHub Desktop.
A small bash script to compile an assembly code into an elf
#!/bin/bash
function usage() {
echo -n "Usage: "
echo "$0 <input_file> [<output_file>]"
echo;
}
function help() {
echo "$0 - A simple program to compile an assembly file into an elf."
usage
}
function checkfirst() {
if [[ ! -f "$1" ]]; then
echo "$1 doesn't exist."
exit 1
fi
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
help
exit 0
fi
}
_in=""
_out=""
if [[ $# == 1 ]]; then
checkfirst "$1"
_in="$1"
_out=$(echo "$1" | cut -d '.' -f 1)
elif [[ $# == 2 ]]; then
checkfirst "$1"
_in="$1"
_out="$2"
else
echo "Invalid arguments provided."; echo
usage
exit 1
fi
gcc -static -nostdlib -o "$_out" "$_in"
.global _start
_start:
.intel_syntax noprefix
mov rax, 60
syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment