Skip to content

Instantly share code, notes, and snippets.

@njh
Last active February 1, 2023 22:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save njh/dca7932ef790d462f6589cf912a20ac0 to your computer and use it in GitHub Desktop.
Linux Hello World machine code for 32-bit ARM, formatted in the binmark format
## 32-bit ARM ELF machine code
# Compile this to a binary using:
# binmark helloworld-arm32.bm > helloworld-arm32
# readelf -a ./helloworld-arm32
# chmod a+rx helloworld-arm32
# ./helloworld-arm32
## ELF File header
# 0x0000
7F "ELF" # Magic number
01 # EI_CLASS (1 = 32-bit)
01 # EI_DATA (1 = little endian)
01 # EI_VERSION (version 1 of ELF)
00 # EI_OSABI (0 = System V)
00 # EI_ABIVERSION
00 00 00 00 # EI_PAD (7 bytes of padding)
00 00 00
# 0x0010:
02 00 # e_type: ET_EXEC (executable file)
28 00 # e_machine: ARM 32
01 00 00 00 # e_version: 1
74 00 01 00 # e_entry: memory address of the entry point to starts executing
34 00 00 00 # e_phoff: offset of the program header table
c0 00 00 00 # e_shoff: offset of the section header table.
00 02 00 05 # e_flags: architecture specific flags
34 00 # e_ehsize: size of this header (52 bytes)
20 00 # e_phentsize: the size of a program header table entry.
02 00 # e_phnum: the number of entries in the program header table.
28 00 # e_shentsize: the size of a section header table entry
04 00 # e_shnum: the number of entries in the section header table
03 00 # e_shstrndx: section names index in the section header table
# 0x0034: Program header
01 00 00 00 # p_type: PT_LOAD = Loadable segment
00 00 00 00 # p_offset: offset of the segment in the file image
00 00 01 00 # p_vaddr: virtual address of the segment in memory
00 00 01 00 # p_paddr: segment's physical address.
98 00 00 00 # p_filesz: size in bytes of the segment in the file image
98 00 00 00 # p_memsz: size in bytes of the segment in memory
05 00 00 00 # p_flags: segment-dependent flags
00 00 01 00 # p_align: byte alignment
# 0x0054: Program header
01 00 00 00 # p_type: PT_LOAD = Loadable segment
98 00 00 00 # p_offset: offset of the segment in the file image
98 00 02 00 # p_vaddr: virtual address of the segment in memory
98 00 02 00 # p_paddr: segment's physical address.
0d 00 00 00 # p_filesz: size in bytes of the segment in the file image
0d 00 00 00 # p_memsz: size in bytes of the segment in memory
06 00 00 00 # p_flags: segment-dependent flags
00 00 01 00 # p_align: byte alignment
# 0x0074: Program Section: .text
01 00 a0 e3 # mov r0, #1 (1 = STDOUT_FILENO)
14 10 9f e5 # ldr r1, [pc, #0x14] (20 = offset to string)
0d 20 a0 e3 # mov r2, #0xd (13 = string length)
04 70 a0 e3 # mov r7, #4 (4 = write syscall)
00 00 00 ef # svc #0 (invoke Linux syscall 0)
00 00 a0 e3 # mov r0, #0 (0 = successful return code)
01 70 a0 e3 # mov r7, #1 (1 = exit syscall)
00 00 00 ef # svc #0 (invoke Linux syscall 0)
98 00 02 00 # Is this the virtual address?
# Where is this documented?
# 0x0098: Program Section: .data
"Hello World!\n"
# 0x00A5: Section Header Strings Table (shstrtab)
"\0" # 0x00: NULL
".shstrtab\0" # 0x01
".text\0" # 0x0b
".data\0" # 0x11
# Padding
00 00 00 00
## Section Header Table
# 0x00C0: 0=NULL
00 00 00 00 # sh_name: offset to the section string table
00 00 00 00 # sh_type: NULL
00 00 00 00 # sh_flags: none
00 00 00 00 # sh_addr: virtual address of the section in memory
00 00 00 00 # sh_offset: offset of the section in the file image.
00 00 00 00 # sh_size: size in bytes of the section in the file image
00 00 00 00 # sh_link: the section index of an associated section
00 00 00 00 # sh_info:
00 00 00 00 # sh_addralign: the required alignment of the section
00 00 00 00 # sh_entsize: the size, in bytes, of each entry
# 0x00E8: 1=.text
0b 00 00 00 # sh_name: offset to the section string table
01 00 00 00 # sh_type: SHT_PROGBITS = Programme Data
06 00 00 00 # sh_flags: none
74 00 01 00 # sh_addr: virtual address of the section in memory
74 00 00 00 # sh_offset: offset of the section in the file image
24 00 00 00 # sh_size: size in bytes of the section in the file image
00 00 00 00 # sh_link: the section index of an associated section
00 00 00 00 # sh_info:
04 00 00 00 # sh_addralign: the required alignment of the section
00 00 00 00 # sh_entsize: the size, in bytes, of each entry
# 0x0110: 2=.data
11 00 00 00 # sh_name: offset to the section string table
01 00 00 00 # sh_type: SHT_PROGBITS = Programme Data
03 00 00 00 # sh_flags: none
98 00 02 00 # sh_addr: virtual address of the section in memory
98 00 00 00 # sh_offset: offset of the section in the file image
0d 00 00 00 # sh_size: size in bytes of the section in the file image
00 00 00 00 # sh_link: the section index of an associated section
00 00 00 00 # sh_info:
01 00 00 00 # sh_addralign: the required alignment of the section
00 00 00 00 # sh_entsize: the size, in bytes, of each entry
# 0x0138: 3=.shstrtab
01 00 00 00 # sh_name: offset to the section string table
03 00 00 00 # sh_type: SHT_STRTAB = 3
00 00 00 00 # sh_flags: none
00 00 00 00 # sh_addr: virtual address of the section in memory
a5 00 00 00 # sh_offset: offset of the section in the file image
17 00 00 00 # sh_size: size in bytes of the section in the file image
00 00 00 00 # sh_link: the section index of an associated section
00 00 00 00 # sh_info:
01 00 00 00 # sh_addralign: the required alignment of the section
00 00 00 00 # sh_entsize: the size, in bytes, of each entry
# 0x0170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment