Lab 4 - Part 2 (x86_64)

In this section, I must write the same programme for the x86 64 platform. This was a little difficult for me because I found aarch64 syntax to be simpler and easier to understand than x86 64 syntax. 

While writing the code for x86_64, I followed a similar procedure. I first printed the loop 10 times without printing the loop counter. I tried it, and it worked on the first try. However, implementing the loop counter proved to be somewhat difficult. I was able to implement it, but when I was storing the count in location #, instead of storing a single byte, it was storing a qword, which overwrote n, and the output was in a single line. To solve the problem, I suffixed the command and registered with b. Here's my code:

.text
.globl    _start

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

_start:
        mov     $min,%r15           /* loop index */

loop:
        /*Start*/

        movq    %r15, %r10
        addq    $'0', %r10
        movq    $msg + 5, %r11
        movb    %r10b, (%r11)

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

        /*End*/

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

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

.section .data
msg:    .ascii "Loop #\n"
len=    . - msg


This was a fantastic opportunity for me. Writing this lab taught me a lot of things. I preferred writing code for aarch64 over x86 64 because it was simpler and more straightforward. Furthermore, aarch64 has more registers than x86 64, making it more flexible.

Comments

Popular posts from this blog

Lab 5 - Algorithm Selection Lab

SPO600 - Project Stage 2

Auto Vectorization