DEV Community

Cover image for 64-bit Assembly Language: Aarch64 VS. X84_64
A Serputov
A Serputov

Posted on

3 2

64-bit Assembly Language: Aarch64 VS. X84_64

In this blog post, you can read about my experiment with assembler on the x86_64 and aarch64 servers.

If you didn't ever see assembler language instructions, here is the ready source code for the Aarch64 system for this lab.

Aarch64

.text
.globl _start

min = 0                          /* starting value for the loop index; note that this is a symbol (constant), not a variable */
max = 31                         /* loop exits when the index hits this number (loop condition is i<max) */

_start:

        mov     x19, min
        mov     x17, 10

loop:
        mov     x0, 1           /* file descriptor: 1 is stdout */
        adr     x1, msg         /* message location (memory address) */
        mov     x2, len         /* message length (bytes) */

        mov     x18, x19        /*mov x19 into x18 */
        udiv    x9, x18, x17
        add     x13, x9, 0x30
        msub    x10, x9, x17, x18 /*get remainder*/
        add     x14, x10, 0x30
        adr     x15, msg
        strb    w13, [x15, 13]

        strb    w14, [x15, 14]
        mov     x8, 64          /* write is syscall #64 */
        svc     0               /* invoke syscall */

        add     x19, x19, 1
        cmp     x19, max
        b.ne    loop

.data

msg:    .ascii      "Hello, World  #\n"
len=    . - msg
Enter fullscreen mode Exit fullscreen mode

This is how we build this code on a specific server

Image description
This is the output of our source code:
Image description
For those interested in how my tree looks right now on the Israel server.
Image description

X84_64

Here is almost the same code, but for a different system.

/* 
   This is a 'hello world' program in x86_64 assembler using the 
   GNU assembler (gas) syntax. Note that this program runs in 64-bit
   mode.

   CTyler, Seneca College, 2014-01-20
   Licensed under GNU GPL v2+
*/

.text
.globl  _start


_start:

        movq     $0, %r15                        /* Loop counter */
        movq     $0x30, %r12                     /* value of 0 in Ascii */

loop:
        movq     $0, %rdx                        /* clearing reminder for division */
        movq     %r15, %rax                      /* set rax to be divide */
        movq     $10, %r10                       /* set divisor */
        div      %r10                            /* divide */
        movq     %rax, %r14                      /* store quotient */
        movq     %rdx, %r13                      /* store remainder */

        add      $0x30, %r14                     /* quotient to ascii */
        add      $0x30, %r13                     /* remainder to ascii */
        mov      %r13b, msg+14                   /* Modify 1 byte inmsg with remainder */

        cmp      %r12, %r14
        mov      %r14b, msg+13                   /* Modify 1 byte in msg with quotient */

        movq     $len, %rdx                      /* message length */
        movq     $msg, %rsi                      /* message location */
        movq     $1, %rdi                                /* file descriptor stdout */
        movq     $1, %rax                                /* syscall sys_write */
        syscall

        inc     %r15                            /* increment counter */
        cmp     $31, %r15                               /* see if we're done */
        jne     loop                            /* if not, loop */

        movq     $0, %rdi                                /* exit status */
        movq     $60, %rax                       /* syscall sys_exit */
        syscall

.section .data

        msg:    .ascii   "Hello World:   \n"
        len = . - msg

~             
Enter fullscreen mode Exit fullscreen mode

On a different server.

Image description

Conclusion

⚠️ Computer Architecture Blog Post: Link

Links

🖇 Follow me on GitHub

🖇 Follow me on Twitter

_p.s This post was made for my Software Portability and Optimization class.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post →

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay