Last active
August 29, 2015 14:19
-
-
Save scottt/a57220efc15d15569a2e to your computer and use it in GitHub Desktop.
hello world in assembler under x86-64 and ARMv7-A Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gdbdis -r hello-arm _start | |
0x00010098 <+0>: 04 27 movs r7, #4 | |
0x0001009a <+2>: 01 20 movs r0, #1 | |
0x0001009c <+4>: 03 49 ldr r1, [pc, #12] ; (0x100ac <_start+20>) | |
0x0001009e <+6>: 5f f0 0d 02 movs.w r2, #13 | |
0x000100a2 <+10>: 00 df svc 0 | |
0x000100a4 <+12>: f8 27 movs r7, #248 ; 0xf8 | |
0x000100a6 <+14>: 00 20 movs r0, #0 | |
0x000100a8 <+16>: 00 df svc 0 | |
0x000100aa <+18>: 00 00 movs r0, r0 | |
0x000100ac <+20>: b0 00 01 00 strheq r0, [r1], -r0 ; <UNPREDICTABLE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.syntax unified | |
.thumb | |
#include <sys/syscall.h> | |
.section .text | |
.global _start | |
.thumb_func | |
_start: | |
/* write(1, "hello, world", 13) */ | |
movs r7, SYS_write | |
movs r0, 1 | |
ldr r1, =hello_str | |
movs r2, hello_str_len | |
svc 0 | |
/* exit_group(0) */ | |
movs r7, SYS_exit_group | |
movs r0, 0 | |
svc 0 | |
.section .rodata | |
hello_str: | |
.ascii "hello, world\n" | |
.set hello_str_len, . - hello_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gdbdis -r hello-x86-64 _start | |
0x00000000004000d4 <+0>: 48 c7 c0 01 00 00 00 mov $0x1,%rax | |
0x00000000004000db <+7>: 48 c7 c7 01 00 00 00 mov $0x1,%rdi | |
0x00000000004000e2 <+14>: 48 c7 c6 02 01 40 00 mov $0x400102,%rsi | |
0x00000000004000e9 <+21>: 48 c7 c2 0d 00 00 00 mov $0xd,%rdx | |
0x00000000004000f0 <+28>: 0f 05 syscall | |
0x00000000004000f2 <+30>: 48 c7 c0 e7 00 00 00 mov $0xe7,%rax | |
0x00000000004000f9 <+37>: 48 c7 c7 00 00 00 00 mov $0x0,%rdi | |
0x0000000000400100 <+44>: 0f 05 syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/syscall.h> | |
.section .text | |
.global _start | |
_start: | |
/* write(1, "hello, world\n", 13) */ | |
mov $SYS_write, %rax | |
mov $1, %rdi | |
mov $hello_str, %rsi | |
mov $hello_str_len, %rdx | |
syscall | |
/* exit_group(0) */ | |
mov $SYS_exit_group, %rax | |
mov $0, %rdi | |
syscall | |
.section .rodata | |
hello_str: | |
.ascii "hello, world\n" | |
.set hello_str_len, . - hello_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment