The 3 "c" programs we will compile are the same as they were on the x86 architecture.
hello.c uses printf
hello2.c uses write
hello3.c uses syscall
The objdump -d commands produces the following output
---------------------------------
hello
0000000000400594 <main>:
400594: a9bf7bfd stp x29, x30, [sp, #-16]!
400598: 910003fd mov x29, sp
40059c: 90000000 adrp x0, 400000 <_init-0x418>
4005a0: 9119c000 add x0, x0, #0x670
4005a4: 97ffffb7 bl 400480 <printf@plt>
4005ac: a8c17bfd ldp x29, x30, [sp], #16
4005b0: d65f03c0 ret
4005b4: 00000000 .inst 0x00000000 ; undefined
---------------------------------
hello2
0000000000400594 <main>:
400594: a9bf7bfd stp x29, x30, [sp, #-16]!
400598: 910003fd mov x29, sp
4005a0: 90000000 adrp x0, 400000 <_init-0x418>
4005a4: 9119e001 add x1, x0, #0x678
4005ac: 97ffffb1 bl 400470 <write@plt>
4005b4: a8c17bfd ldp x29, x30, [sp], #16
4005b8: d65f03c0 ret
4005bc: 00000000 .inst 0x00000000 ; undefined
---------------------------------
hello3
0000000000400594 <main>:
400594: a9bf7bfd stp x29, x30, [sp, #-16]!
400598: 910003fd mov x29, sp
4005a0: 90000000 adrp x0, 400000 <_init-0x418>
4005a4: 9119e002 add x2, x0, #0x678
4005b0: 97ffffb4 bl 400480 <syscall@plt>
4005b8: a8c17bfd ldp x29, x30, [sp], #16
4005bc: d65f03c0 ret
---------------------------------
---------------------------------
ANALYSIS
---------------------------------
---------------------------------
Again the printf output is smaller compared to the write and syscall. All outputs share a similar format with write and syscall being very clse in syntax other than a few different registers being used.
========================================================================
COMPILING ASSEBMLY LANGUAGE ON AARCH64
========================================================================
There is only one file to compile in assembly .s format, and it is similar to the syntax used in the X86 NASM assembler language
---------------------------------
cat hello.s
.text
.globl _start
_start:
mov x0, 1 /* file descriptor: 1 is stdout */
adr x1, msg /* message location (memory address) */
mov x2, len /* message length (bytes) */
mov x8, 64 /* write is syscall #64 */
svc 0 /* invoke syscall */
mov x0, 0 /* status -> 0 */
mov x8, 93 /* exit is syscall #93 */
svc 0 /* invoke syscall */
.data
msg: .ascii "Hello, world!\n"
len= . - msg
--------------------------------
---------------------------------
The output after running objdump
--------------------------------
--------------------------------
hello: file format elf64-littleaarch64
Disassembly of section .text:
00000000004000b0 <_start>:
4000b0: d2800020 mov x0, #0x1 // Length of the buffer
4000b4: 100800e1 adr x1, 4100d0 <msg> // Getting address of "HEllo World!"
4000b8: d28001c2 mov x2, #0xe // Setting file descriptor to write
4000bc: d2800808 mov x8, #0x40 // The CAll ID the system will use
4000c0: d4000001 svc #0x0 // Invoke syscall
4000c4: d2800000 mov x0, #0x0 //
4000c8: d2800ba8 mov x8, #0x5d //
4000cc: d4000001 svc #0x0 // exit program
--------------------------------
--------------------------------
Compared to the output of the original hello.c cource code
--------------------------------
--------------------------------
/* Hello World in traditional C using printf() */
#include <stdio.h>
int main() {
printf("Hello World!\n");
}
Comments