🇺🇸 English | 🇪🇸 Español
Small shell helper to assemble, link and run Assembly programs quickly from the terminal.
Instead of running nasm and ld manually every time, this function assembles a .asm file, links it, and immediately executes the resulting binary.
asm program.asmThis will:
- Assemble the file with
nasm - Generate an object file (
.o) - Link it using
ld - Run the compiled binary
Example:
asm hello.asmYou need:
- nasm
- ld (usually included with
binutils) - a POSIX shell (bash / zsh)
Install dependencies if you don't have them.
sudo apt install nasm binutilssudo pacman -S nasm binutilssudo dnf install nasm binutilsCopy the function into your shell config file.
For bash:
~/.bashrcFor zsh:
~/.zshrcThen paste:
asm() {
local file="$1"
if [[ -z "$file" ]]; then
echo "Usage: asm file.asm"
return 1
fi
if [[ ! -f "$file" ]]; then
echo "File not found"
return 1
fi
local name="${file%.asm}"
nasm -f elf64 -o "$name.o" "$file" &&
ld -o "$name" "$name.o" &&
"./$name"
}Reload your shell:
source ~/.zshrcor
source ~/.bashrcCreate a script:
sudo nano /usr/local/bin/asmPaste:
#!/usr/bin/env bash
file="$1"
[ -z "$file" ] && echo "Usage: asm file.asm" && exit 1
[ ! -f "$file" ] && echo "File not found" && exit 1
name="${file%.asm}"
nasm -f elf64 -o "$name.o" "$file" &&
ld -o "$name" "$name.o" &&
"./$name"Make it executable:
sudo chmod +x /usr/local/bin/asmNow you can run:
asm program.asmfrom anywhere.
Just a tiny utility to remove friction when experimenting with Assembly programs.
Assemble → link → run → repeat.
Made with <3 by URDev