Run assembly scripts from your terminal without compiling

https://www.youtube.com/watch?v=kNKuRdoaNII

Source code:

#!/usr/bin/env bash

# runasm - Assemble, link, and run multiple assembly files, then delete them.
if [[ $# -eq 0 ]]; then
    echo "Usage: runasm  [ ...]"
    echo "  - Assemble, link, and run multiple assembly files, then delete them."
    echo "  - Name of executable is the name of the first file without extension."
    exit 1
fi

object_files=()
executable_file=${1%.*}

for assembly_file in "$@"; do
    # Avengers, assemble!
    object_file="${assembly_file%.*}.o"
    as "${assembly_file}" -o "${object_file}"
    if [[ $? -ne 0 ]]; then
        exit 1
    fi
    object_files+=("${object_file}")
done

# Link
ld "${object_files[@]}" -o "${executable_file}"
if [[ $? -ne 0 ]]; then
    exit 1
fi

# Run, remove created files, and return exit code
./"${executable_file}"
exit_code=$?
rm "${object_files[@]}" "${executable_file}" > /dev/null 2>&1
exit "${exit_code}"
34 points · 9 comments · view on lemmy.world

9 Comments

jsdz@lemmy.ml · 52 pts · 2y

I have two reactions: 1. The headline is rather silly. 2. There's no way this little script, although it might conceivably be useful to someone, needs to be a youtube video.

Poe@lemmy.world · 22 pts · 2y (2 replies)

Isn't the whole point of assembly that there is no compiler?

SpaceNoodle@lemmy.world · 18 pts · 2y

Right, they just use an assembler and a linker ...

stardreamer@lemmy.blahaj.zone · 6 pts · 2y

I mean they're not wrong...

This is why my next book will be titled "how to cook dinner without a compiler, GCC 4 to GCC 11 compatible!"

sir_reginald@lemmy.world · 18 pts · 2y (1 reply)

I was going to click on this until I saw it was a video.

spaghetti_carbanana@krabb.org · 4 pts · 2y

I need this on a t-shirt

otl@lemmy.sdf.org · 3 pts · 2y

I'm still super confused by this user's posts lol. I get that (some? most?) of it is satire... but then why all social media engagement farming hashtag nonsense? Or is this all part of the satire...?

PipedLinkBot@feddit.rocks · 1 pts · 2y

Here is an alternative Piped link(s):

https://piped.video/watch?v=kNKuRdoaNII

Source code:

Piped is a privacy-respecting open-source alternative frontend to YouTube.

I'm open-source; check me out at GitHub.

RastislavKish@lemmy.ml · 1 pts · 2y

Perhaps we should reconsider the definition of write-only scripts.