Hacker News new | past | comments | ask | show | jobs | submit login

You don't have to use AT&T syntax in GAS. I wrote a blog post a while back showing how you can use Intel syntax instead, and skip a whole lot of % characters while you are at it.

http://madscientistlabs.blogspot.ca/2013/07/gas-problems.htm...




Wow, thanks for that! It's still a little painful, but here goes:

    # file:hello.s
    #
    # Translated to gas syntax.
    # assemble with:
    # as --64 -o hello.o hello.s
    # link with:
    # ld -o hellos hellos.o
    #
    # Modifications to original code considered trivial and to be
    # public domain.
    #
    # Support intel syntal vs. ATT and don't use % before register names
    .intel_syntax noprefix

    .section .data
        msg: .asciz "hello, world!\n"

    .section .text

    .global _start

    _start:
        # write syscal
        mov     rax, 1
        # file descritor, standard output
        mov     rdi, 1
        # message address
        mov     rsi, OFFSET FLAT:msg
        # length of message
        mov     rdx, 14
        # call write syscall
        syscall

        #
        mov    rax, 60
        mov    rdi, 0

        syscall
Note the trailing new-line in the message (and length change from 13 to 14). For nasm:

    section .data
        msg db      "hello, world!",`\n`
    ;; Remember to use 14 for string length!


Try these changes instead. Untested, but it should work

    # String is read only.
    .section .rodata
        msg: .asciz "hello, world!\n"
    # Put string length in a variable instead
        .set STR_SIZE, . - msg
    # <snip>
    mov     rdx, STR_SIZE




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: