hello.s
.text .global _start _start: mov x2, #13 // x2 length adr x1, msg // x1 string address mov x0, #1 // x0 stdout mov x8, #64 svc #0 // sys_write mov x0, xzr mov x8, #93 svc #0 // exit msg: .asciz "hello, world\n"
asでアセンブルしてオブジェクトファイルを作り、リンカを使って実行ファイルを作成する
$ ld -o hello hello.o
$ ./hello
hello, world
ファイルサイズ
$ ls -l hello*
-rwxrwxr-x 1 vagrant vagrant 936 Jan 19 18:14 hello
-rw-rw-r– 1 vagrant vagrant 816 Jan 19 18:14 hello.o
-rw-rw-r– 1 vagrant vagrant 386 Jan 19 17:48 hello.s
シンボル情報の表示
$ nm hello
00000000004100a6 T __bss_end__
00000000004100a6 T _bss_end__
00000000004100a6 T __bss_start
00000000004100a6 T __bss_start__
00000000004100a6 T _edata
00000000004100a8 T __end__
00000000004100a8 T _end
0000000000400098 t msg
0000000000400078 T _start
objdumpによる逆アセンブル
$ objdump -d hello
hello: file format elf64-littleaarch64
Disassembly of section .text:
0000000000400078 <_start>:
400078: d28001a2 mov x2, #0xd // #13
40007c: 100000e1 adr x1, 400098
400080: d2800020 mov x0, #0x1 // #1
400084: d2800808 mov x8, #0x40 // #64
400088: d4000001 svc #0x0
40008c: aa1f03e0 mov x0, xzr
400090: d2800ba8 mov x8, #0x5d // #93
400094: d4000001 svc #0x0
0000000000400098
400098: 6c6c6568 .word 0x6c6c6568
40009c: 77202c6f .word 0x77202c6f
4000a0: 646c726f .word 0x646c726f
4000a4: Address 0x00000000004000a4 is out of bounds.
16進数、32ビットなどで出力も可
$ strings hello
hello, world
hello.o
__bss_start__
__bss_end__
__bss_start
__end__
_edata
_end
.symtab
.strtab
.shstrtab
.text
includeした場合
.include "stdio.s" .text .global _start _start: adr x0, msg bl OutAsciiZ bl Exit msg: .asciz "Hello Hpscript\n"
$ as -o sample.o sample.s
$ ld -o sample sample.o
$ ./sample