top of page

Lab 4: Assembly Language on Aarch64 architecture

Writer's picture: jadach1jadach1

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>

4005a8: 52800000 mov w0, #0x0 // #0

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

40059c: d28001a2 mov x2, #0xd // #13

4005a0: 90000000 adrp x0, 400000 <_init-0x418>

4005a4: 9119e001 add x1, x0, #0x678

4005a8: 52800020 mov w0, #0x1 // #1

4005ac: 97ffffb1 bl 400470 <write@plt>

4005b0: 52800000 mov w0, #0x0 // #0

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

40059c: 528001a3 mov w3, #0xd // #13

4005a0: 90000000 adrp x0, 400000 <_init-0x418>

4005a4: 9119e002 add x2, x0, #0x678

4005a8: 52800021 mov w1, #0x1 // #1

4005ac: d2800800 mov x0, #0x40 // #64

4005b0: 97ffffb4 bl 400480 <syscall@plt>

4005b4: 52800000 mov w0, #0x0 // #0

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");

}


 
 
 

Recent Posts

See All

Closing Thoughts

For my final blog post I would like to discuss what I have learned and plan to utilize in the future from this course. So although I was...

Comments


bottom of page