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.
nasmThe 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:
nasm -f elf64 hello.asm -o hello.ofile hello.ohello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not strippedThat 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.
ld vs. Letting gcc Do ItThe 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:
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.
objdump -d -M intelGoing 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 -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 syscallThis 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.
Two commands, every time, so we chain them. When a lesson says "assemble and run," this is the line:
nasm -f elf64 hello.asm -o hello.o && ld hello.o -o hello && ./helloas/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.