Skip to content

Instantly share code, notes, and snippets.

@michidk
Created October 10, 2026 11:17
Show Gist options
  • Select an option

  • Save michidk/a2d048a126956ec4f6cf335f9782c37a to your computer and use it in GitHub Desktop.

Select an option

Save michidk/a2d048a126956ec4f6cf335f9782c37a to your computer and use it in GitHub Desktop.
153-byte Linux ELF64 Hello World with separate headers and code; relies on zero initial RAX/RBX/RDX; GNU binutils build commands included
/* Build with GNU binutils:
* as --64 hello153.S -o hello153.o
* objcopy -O binary -j .text hello153.o hello153
* chmod +x hello153
* A 153-byte Linux ELF64 executable; headers, message and code do not overlap.
*/
.intel_syntax noprefix
.section .text
.set base, 0x400000
image:
.byte 0x7f
.ascii "ELF"
.byte 2, 1, 1, 0
.zero 8
.short 2, 0x3e
.long 1
.quad base + (start - image)
.quad phdr - image
.quad 0
.long 0
.short 64, 56, 1, 0, 0, 0
phdr:
.long 1, 5
.quad 0
.quad base, base
.quad image_end - image, image_end - image
.quad 0x1000
msg:
.ascii "Hello, World!\n"
msg_end:
start:
/* Linux static ELF entry: RAX=RBX=RDX=0. No PT_INTERP. */
mov al, 1
mov edi, eax
/* Fixed ET_EXEC address fits in 32 bits: 5 bytes instead of LEA's 6. */
mov esi, OFFSET FLAT:base + (msg - image)
mov dl, msg_end - msg
syscall
/* Each XCHG is one byte. Discard ANY write result into EBX,
* then move zero to EDI and the known stdout fd (1) to EAX.
* MOV AL,60 is now safe even when write returned a negative errno.
*/
xchg eax, ebx
xchg eax, edi
mov al, 60
syscall
image_end:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment