Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. assembling
3 min read

Assembling & Linking

Writing assembly is only half the job; you have to turn that text into a program the kernel will run. That happens in two steps — assemble, then link — and this lesson walks the whole path from hello.asm to a running executable.

hello.asm source nasm -f elf64 hello.o object file ld hello executable

Assembling with nasm

The assembler translates your .asm text into machine code, packaged in an object file. For 64-bit Linux, that is nasm -f elf64 — the -f elf64 picks the output format (a 64-bit ELF object). Afterward, file shows what we produced:

assembling
$ nasm -f elf64 hello.asm -o hello.o$ file hello.ohello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

That is a relocatable object, not an executable. It holds your assembled machine code but still has loose ends — unresolved addresses and no entry point for the kernel to jump to. To get something runnable, you link it.

Linking: ld vs. Letting gcc Do It

The linker resolves those loose ends and produces an executable with a defined entry point. Our program defines its own _start label and talks to the kernel directly with syscall, so it needs nothing from the C library — we link it straight with ld, then run the result:

assembling
$ ld hello.o -o hello$ ./helloHello, world!

That works because _start is the symbol the kernel jumps to first. If instead you wrote a main and called C functions like printf, you would let gcc do the linking (gcc hello.o -o hello): gcc pulls in the C runtime, which provides the real _start, sets things up, and then calls your main. Rule of thumb — raw syscalls and your own _start → link with ld; using libc and a main → link with gcc.

Disassembling with objdump -d -M intel

Going the other direction, objdump turns a compiled binary back into assembly. The -d disassembles the code sections, and -M intel asks for Intel syntax (without it you get AT&T — see the previous lesson):

objdump
$ objdump -d -M intel hello0000000000401000 <_start>:  401000:       b8 01 00 00 00          mov    eax,0x1  401005:       bf 01 00 00 00          mov    edi,0x1  40100a:       48 be 00 20 40 00 00    movabs rsi,0x402000  401011:       00 00 00  401014:       ba 0e 00 00 00          mov    edx,0xe  401019:       0f 05                   syscall  40101b:       b8 3c 00 00 00          mov    eax,0x3c  401020:       bf 00 00 00 00          mov    edi,0x0  401025:       0f 05                   syscall

This is how you check what the assembler actually produced, and it is the first thing you reach for when inspecting a binary you did not write.

The Build One-Liner This Course Uses

Two commands, every time, so we chain them. When a lesson says "assemble and run," this is the line:

bash
nasm -f elf64 hello.asm -o hello.o && ld hello.o -o hello && ./hello
NASM writes Intel syntax; the GNU assembler (as/GAS, what gcc uses internally) writes AT&T by default. That is the same Intel-vs-AT&T split from the previous lesson — it reaches all the way down into which assembler you pick.