Compile/run assembler in Linux?










53















I'm fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn't find anything specific to Linux.
So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package?










share|improve this question
























  • I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

    – Matt Joiner
    Jul 23 '10 at 2:21











  • These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

    – Rafe Kettler
    Jul 23 '10 at 3:01











  • My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

    – Justin
    Jul 23 '10 at 3:28















53















I'm fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn't find anything specific to Linux.
So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package?










share|improve this question
























  • I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

    – Matt Joiner
    Jul 23 '10 at 2:21











  • These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

    – Rafe Kettler
    Jul 23 '10 at 3:01











  • My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

    – Justin
    Jul 23 '10 at 3:28













53












53








53


27






I'm fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn't find anything specific to Linux.
So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package?










share|improve this question
















I'm fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn't find anything specific to Linux.
So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package?







linux ubuntu x86 assembly






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 28 '17 at 0:31









Mateusz Piotrowski

3,92063051




3,92063051










asked Jul 23 '10 at 2:11









Rafe KettlerRafe Kettler

56.1k16131141




56.1k16131141












  • I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

    – Matt Joiner
    Jul 23 '10 at 2:21











  • These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

    – Rafe Kettler
    Jul 23 '10 at 3:01











  • My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

    – Justin
    Jul 23 '10 at 3:28

















  • I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

    – Matt Joiner
    Jul 23 '10 at 2:21











  • These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

    – Rafe Kettler
    Jul 23 '10 at 3:01











  • My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

    – Justin
    Jul 23 '10 at 3:28
















I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

– Matt Joiner
Jul 23 '10 at 2:21





I'm in the same boat. I've never really picked up asm on Linux because there's no real presence. Maybe it's because on Windows cracking is all the rage.

– Matt Joiner
Jul 23 '10 at 2:21













These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

– Rafe Kettler
Jul 23 '10 at 3:01





These don't completely answer my question. I still want to know what console commands you would use to compile and run programs in NASM or gas

– Rafe Kettler
Jul 23 '10 at 3:01













My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

– Justin
Jul 23 '10 at 3:28





My preference is NASM. I give you some info on how to get it up and running on Ubuntu below.

– Justin
Jul 23 '10 at 3:28












8 Answers
8






active

oldest

votes


















43














The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.



gas uses AT&T syntax (guide: https://stackoverflow.com/tags/att/info):



mnemonic source, destination


nasm uses Intel style (guide: https://stackoverflow.com/tags/intel-syntax/info):



mnemonic destination, source


Either one will probably do what you need. GAS also has an Intel-syntax mode, which is a lot like MASM, not NASM.




Try out this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html



See also more links to guides and docs in Stack Overflow's x86 tag wiki






share|improve this answer




















  • 1





    Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

    – Rafe Kettler
    Jul 23 '10 at 3:39







  • 1





    gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

    – snemarch
    Sep 29 '10 at 14:20


















55














The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.



However, GCC makes a great front-end. It can assemble .s files for you. For example:



$ cat >hello.s <<"EOF"
.section .rodata # read-only static data
.globl hello
hello:
.string "Hello, world!" # zero-terminated C string

.text
.global main
main:
push %rbp
mov %rsp, %rbp # create a stack frame

mov $hello, %edi # put the address of hello into RDI
call puts # as the first arg for puts

mov $0, %eax # return value = 0. Normally xor %eax,%eax
leave # tear down the stack frame
ret # pop the return address off the stack into RIP
EOF
$ gcc hello.s -no-pie -o hello
$ ./hello
Hello, world!


The code above is x86-64. If you want to make a position-independent executable (PIE), you'd need lea hello(%rip), %rdi, and call puts@plt.



A non-PIE executable (position-dependent) can use 32-bit absolute addressing for static data, but a PIE should use RIP-relative LEA. (See also Difference between movq and movabsq in x86-64 neither movq nor movabsq are a good choice.)



If you wanted to write 32-bit code, the calling convention is different, and RIP-relative addressing isn't available. (So you'd push $hello before the call, and pop the stack args after.)




You can also compile C/C++ code directly to assembly if you're curious how something works:



$ cat >hello.c <<EOF
#include <stdio.h>
int main(void)
printf("Hello, world!n");
return 0;

EOF
$ gcc -S hello.c -o hello.s


See also How to remove "noise" from GCC/clang assembly output? for more about looking at compiler output, and writing useful small functions that will compile to interesting output.






share|improve this answer
































    20














    If you are using NASM, the command-line is just



    nasm -felf32 -g -Fdwarf file.asm -o file.o


    where 'file.asm' is your assembly file (code) and 'file.o' is an object file you can link with gcc -m32 or ld -melf_i386. (Assembling with nasm -felf64 will make a 64-bit object file, but the hello world example below uses 32-bit system calls, and won't work in a PIE executable.)



    Here is some more info:



    http://www.nasm.us/doc/nasmdoc2.html#section-2.1



    You can install NASM in Ubuntu with the following command:



    apt-get install nasm


    Here is a basic Hello World in Linux assembly to whet your appetite:



    http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html



    I hope this is what you were asking...






    share|improve this answer

























    • Hello World example is a broken link!

      – Matt Fletcher
      Nov 8 '13 at 17:24











    • tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

      – imbellish
      Apr 13 '17 at 6:44


















    8














    There is also FASM for Linux.



    format ELF executable

    segment readable executable

    start:
    mov eax, 4
    mov ebx, 1
    mov ecx, hello_msg
    mov edx, hello_size
    int 80h

    mov eax, 1
    mov ebx, 0
    int 80h

    segment readable writeable

    hello_msg db "Hello World!",10,0
    hello_size = $-hello_msg


    It comiles with



    fasm hello.asm hello





    share|improve this answer






























      7














      My suggestion would be to get the book Programming From Ground Up:



      http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf



      That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.






      share|improve this answer
































        4














        The assembler(GNU) is as(1)






        share|improve this answer






























          3














          3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.



          http://www.tortall.net/projects/yasm/






          share|improve this answer






























            0














            For Ubuntu 18.04 installnasm . Open the terminal and type:



            sudo apt install as31 nasm



            nasm docs



            For compiling and running:



            nasm -f elf64 example.asm # assemble the program 
            ld -s -o example example.o # link the object file nasm produced into an executable file
            ./example # example is an executable file





            share|improve this answer

























            • as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

              – Peter Cordes
              Nov 14 '18 at 21:50










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3314919%2fcompile-run-assembler-in-linux%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            8 Answers
            8






            active

            oldest

            votes








            8 Answers
            8






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            43














            The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.



            gas uses AT&T syntax (guide: https://stackoverflow.com/tags/att/info):



            mnemonic source, destination


            nasm uses Intel style (guide: https://stackoverflow.com/tags/intel-syntax/info):



            mnemonic destination, source


            Either one will probably do what you need. GAS also has an Intel-syntax mode, which is a lot like MASM, not NASM.




            Try out this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html



            See also more links to guides and docs in Stack Overflow's x86 tag wiki






            share|improve this answer




















            • 1





              Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

              – Rafe Kettler
              Jul 23 '10 at 3:39







            • 1





              gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

              – snemarch
              Sep 29 '10 at 14:20















            43














            The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.



            gas uses AT&T syntax (guide: https://stackoverflow.com/tags/att/info):



            mnemonic source, destination


            nasm uses Intel style (guide: https://stackoverflow.com/tags/intel-syntax/info):



            mnemonic destination, source


            Either one will probably do what you need. GAS also has an Intel-syntax mode, which is a lot like MASM, not NASM.




            Try out this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html



            See also more links to guides and docs in Stack Overflow's x86 tag wiki






            share|improve this answer




















            • 1





              Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

              – Rafe Kettler
              Jul 23 '10 at 3:39







            • 1





              gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

              – snemarch
              Sep 29 '10 at 14:20













            43












            43








            43







            The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.



            gas uses AT&T syntax (guide: https://stackoverflow.com/tags/att/info):



            mnemonic source, destination


            nasm uses Intel style (guide: https://stackoverflow.com/tags/intel-syntax/info):



            mnemonic destination, source


            Either one will probably do what you need. GAS also has an Intel-syntax mode, which is a lot like MASM, not NASM.




            Try out this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html



            See also more links to guides and docs in Stack Overflow's x86 tag wiki






            share|improve this answer















            The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.



            gas uses AT&T syntax (guide: https://stackoverflow.com/tags/att/info):



            mnemonic source, destination


            nasm uses Intel style (guide: https://stackoverflow.com/tags/intel-syntax/info):



            mnemonic destination, source


            Either one will probably do what you need. GAS also has an Intel-syntax mode, which is a lot like MASM, not NASM.




            Try out this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html



            See also more links to guides and docs in Stack Overflow's x86 tag wiki







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 22:27









            Peter Cordes

            128k18190327




            128k18190327










            answered Jul 23 '10 at 2:24









            GeorgeGeorge

            1,78011311




            1,78011311







            • 1





              Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

              – Rafe Kettler
              Jul 23 '10 at 3:39







            • 1





              gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

              – snemarch
              Sep 29 '10 at 14:20












            • 1





              Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

              – Rafe Kettler
              Jul 23 '10 at 3:39







            • 1





              gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

              – snemarch
              Sep 29 '10 at 14:20







            1




            1





            Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

            – Rafe Kettler
            Jul 23 '10 at 3:39






            Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux

            – Rafe Kettler
            Jul 23 '10 at 3:39





            1




            1





            gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

            – snemarch
            Sep 29 '10 at 14:20





            gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.

            – snemarch
            Sep 29 '10 at 14:20













            55














            The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.



            However, GCC makes a great front-end. It can assemble .s files for you. For example:



            $ cat >hello.s <<"EOF"
            .section .rodata # read-only static data
            .globl hello
            hello:
            .string "Hello, world!" # zero-terminated C string

            .text
            .global main
            main:
            push %rbp
            mov %rsp, %rbp # create a stack frame

            mov $hello, %edi # put the address of hello into RDI
            call puts # as the first arg for puts

            mov $0, %eax # return value = 0. Normally xor %eax,%eax
            leave # tear down the stack frame
            ret # pop the return address off the stack into RIP
            EOF
            $ gcc hello.s -no-pie -o hello
            $ ./hello
            Hello, world!


            The code above is x86-64. If you want to make a position-independent executable (PIE), you'd need lea hello(%rip), %rdi, and call puts@plt.



            A non-PIE executable (position-dependent) can use 32-bit absolute addressing for static data, but a PIE should use RIP-relative LEA. (See also Difference between movq and movabsq in x86-64 neither movq nor movabsq are a good choice.)



            If you wanted to write 32-bit code, the calling convention is different, and RIP-relative addressing isn't available. (So you'd push $hello before the call, and pop the stack args after.)




            You can also compile C/C++ code directly to assembly if you're curious how something works:



            $ cat >hello.c <<EOF
            #include <stdio.h>
            int main(void)
            printf("Hello, world!n");
            return 0;

            EOF
            $ gcc -S hello.c -o hello.s


            See also How to remove "noise" from GCC/clang assembly output? for more about looking at compiler output, and writing useful small functions that will compile to interesting output.






            share|improve this answer





























              55














              The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.



              However, GCC makes a great front-end. It can assemble .s files for you. For example:



              $ cat >hello.s <<"EOF"
              .section .rodata # read-only static data
              .globl hello
              hello:
              .string "Hello, world!" # zero-terminated C string

              .text
              .global main
              main:
              push %rbp
              mov %rsp, %rbp # create a stack frame

              mov $hello, %edi # put the address of hello into RDI
              call puts # as the first arg for puts

              mov $0, %eax # return value = 0. Normally xor %eax,%eax
              leave # tear down the stack frame
              ret # pop the return address off the stack into RIP
              EOF
              $ gcc hello.s -no-pie -o hello
              $ ./hello
              Hello, world!


              The code above is x86-64. If you want to make a position-independent executable (PIE), you'd need lea hello(%rip), %rdi, and call puts@plt.



              A non-PIE executable (position-dependent) can use 32-bit absolute addressing for static data, but a PIE should use RIP-relative LEA. (See also Difference between movq and movabsq in x86-64 neither movq nor movabsq are a good choice.)



              If you wanted to write 32-bit code, the calling convention is different, and RIP-relative addressing isn't available. (So you'd push $hello before the call, and pop the stack args after.)




              You can also compile C/C++ code directly to assembly if you're curious how something works:



              $ cat >hello.c <<EOF
              #include <stdio.h>
              int main(void)
              printf("Hello, world!n");
              return 0;

              EOF
              $ gcc -S hello.c -o hello.s


              See also How to remove "noise" from GCC/clang assembly output? for more about looking at compiler output, and writing useful small functions that will compile to interesting output.






              share|improve this answer



























                55












                55








                55







                The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.



                However, GCC makes a great front-end. It can assemble .s files for you. For example:



                $ cat >hello.s <<"EOF"
                .section .rodata # read-only static data
                .globl hello
                hello:
                .string "Hello, world!" # zero-terminated C string

                .text
                .global main
                main:
                push %rbp
                mov %rsp, %rbp # create a stack frame

                mov $hello, %edi # put the address of hello into RDI
                call puts # as the first arg for puts

                mov $0, %eax # return value = 0. Normally xor %eax,%eax
                leave # tear down the stack frame
                ret # pop the return address off the stack into RIP
                EOF
                $ gcc hello.s -no-pie -o hello
                $ ./hello
                Hello, world!


                The code above is x86-64. If you want to make a position-independent executable (PIE), you'd need lea hello(%rip), %rdi, and call puts@plt.



                A non-PIE executable (position-dependent) can use 32-bit absolute addressing for static data, but a PIE should use RIP-relative LEA. (See also Difference between movq and movabsq in x86-64 neither movq nor movabsq are a good choice.)



                If you wanted to write 32-bit code, the calling convention is different, and RIP-relative addressing isn't available. (So you'd push $hello before the call, and pop the stack args after.)




                You can also compile C/C++ code directly to assembly if you're curious how something works:



                $ cat >hello.c <<EOF
                #include <stdio.h>
                int main(void)
                printf("Hello, world!n");
                return 0;

                EOF
                $ gcc -S hello.c -o hello.s


                See also How to remove "noise" from GCC/clang assembly output? for more about looking at compiler output, and writing useful small functions that will compile to interesting output.






                share|improve this answer















                The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.



                However, GCC makes a great front-end. It can assemble .s files for you. For example:



                $ cat >hello.s <<"EOF"
                .section .rodata # read-only static data
                .globl hello
                hello:
                .string "Hello, world!" # zero-terminated C string

                .text
                .global main
                main:
                push %rbp
                mov %rsp, %rbp # create a stack frame

                mov $hello, %edi # put the address of hello into RDI
                call puts # as the first arg for puts

                mov $0, %eax # return value = 0. Normally xor %eax,%eax
                leave # tear down the stack frame
                ret # pop the return address off the stack into RIP
                EOF
                $ gcc hello.s -no-pie -o hello
                $ ./hello
                Hello, world!


                The code above is x86-64. If you want to make a position-independent executable (PIE), you'd need lea hello(%rip), %rdi, and call puts@plt.



                A non-PIE executable (position-dependent) can use 32-bit absolute addressing for static data, but a PIE should use RIP-relative LEA. (See also Difference between movq and movabsq in x86-64 neither movq nor movabsq are a good choice.)



                If you wanted to write 32-bit code, the calling convention is different, and RIP-relative addressing isn't available. (So you'd push $hello before the call, and pop the stack args after.)




                You can also compile C/C++ code directly to assembly if you're curious how something works:



                $ cat >hello.c <<EOF
                #include <stdio.h>
                int main(void)
                printf("Hello, world!n");
                return 0;

                EOF
                $ gcc -S hello.c -o hello.s


                See also How to remove "noise" from GCC/clang assembly output? for more about looking at compiler output, and writing useful small functions that will compile to interesting output.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 14 '18 at 22:22









                Peter Cordes

                128k18190327




                128k18190327










                answered Jul 23 '10 at 3:44









                Jay ConrodJay Conrod

                19.7k1581104




                19.7k1581104





















                    20














                    If you are using NASM, the command-line is just



                    nasm -felf32 -g -Fdwarf file.asm -o file.o


                    where 'file.asm' is your assembly file (code) and 'file.o' is an object file you can link with gcc -m32 or ld -melf_i386. (Assembling with nasm -felf64 will make a 64-bit object file, but the hello world example below uses 32-bit system calls, and won't work in a PIE executable.)



                    Here is some more info:



                    http://www.nasm.us/doc/nasmdoc2.html#section-2.1



                    You can install NASM in Ubuntu with the following command:



                    apt-get install nasm


                    Here is a basic Hello World in Linux assembly to whet your appetite:



                    http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html



                    I hope this is what you were asking...






                    share|improve this answer

























                    • Hello World example is a broken link!

                      – Matt Fletcher
                      Nov 8 '13 at 17:24











                    • tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                      – imbellish
                      Apr 13 '17 at 6:44















                    20














                    If you are using NASM, the command-line is just



                    nasm -felf32 -g -Fdwarf file.asm -o file.o


                    where 'file.asm' is your assembly file (code) and 'file.o' is an object file you can link with gcc -m32 or ld -melf_i386. (Assembling with nasm -felf64 will make a 64-bit object file, but the hello world example below uses 32-bit system calls, and won't work in a PIE executable.)



                    Here is some more info:



                    http://www.nasm.us/doc/nasmdoc2.html#section-2.1



                    You can install NASM in Ubuntu with the following command:



                    apt-get install nasm


                    Here is a basic Hello World in Linux assembly to whet your appetite:



                    http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html



                    I hope this is what you were asking...






                    share|improve this answer

























                    • Hello World example is a broken link!

                      – Matt Fletcher
                      Nov 8 '13 at 17:24











                    • tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                      – imbellish
                      Apr 13 '17 at 6:44













                    20












                    20








                    20







                    If you are using NASM, the command-line is just



                    nasm -felf32 -g -Fdwarf file.asm -o file.o


                    where 'file.asm' is your assembly file (code) and 'file.o' is an object file you can link with gcc -m32 or ld -melf_i386. (Assembling with nasm -felf64 will make a 64-bit object file, but the hello world example below uses 32-bit system calls, and won't work in a PIE executable.)



                    Here is some more info:



                    http://www.nasm.us/doc/nasmdoc2.html#section-2.1



                    You can install NASM in Ubuntu with the following command:



                    apt-get install nasm


                    Here is a basic Hello World in Linux assembly to whet your appetite:



                    http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html



                    I hope this is what you were asking...






                    share|improve this answer















                    If you are using NASM, the command-line is just



                    nasm -felf32 -g -Fdwarf file.asm -o file.o


                    where 'file.asm' is your assembly file (code) and 'file.o' is an object file you can link with gcc -m32 or ld -melf_i386. (Assembling with nasm -felf64 will make a 64-bit object file, but the hello world example below uses 32-bit system calls, and won't work in a PIE executable.)



                    Here is some more info:



                    http://www.nasm.us/doc/nasmdoc2.html#section-2.1



                    You can install NASM in Ubuntu with the following command:



                    apt-get install nasm


                    Here is a basic Hello World in Linux assembly to whet your appetite:



                    http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html



                    I hope this is what you were asking...







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 14 '18 at 21:55









                    Peter Cordes

                    128k18190327




                    128k18190327










                    answered Jul 23 '10 at 3:26









                    JustinJustin

                    7,64243141




                    7,64243141












                    • Hello World example is a broken link!

                      – Matt Fletcher
                      Nov 8 '13 at 17:24











                    • tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                      – imbellish
                      Apr 13 '17 at 6:44

















                    • Hello World example is a broken link!

                      – Matt Fletcher
                      Nov 8 '13 at 17:24











                    • tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                      – imbellish
                      Apr 13 '17 at 6:44
















                    Hello World example is a broken link!

                    – Matt Fletcher
                    Nov 8 '13 at 17:24





                    Hello World example is a broken link!

                    – Matt Fletcher
                    Nov 8 '13 at 17:24













                    tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                    – imbellish
                    Apr 13 '17 at 6:44





                    tldp.org/HOWTO/Assembly-HOWTO/hello.html#AEN867

                    – imbellish
                    Apr 13 '17 at 6:44











                    8














                    There is also FASM for Linux.



                    format ELF executable

                    segment readable executable

                    start:
                    mov eax, 4
                    mov ebx, 1
                    mov ecx, hello_msg
                    mov edx, hello_size
                    int 80h

                    mov eax, 1
                    mov ebx, 0
                    int 80h

                    segment readable writeable

                    hello_msg db "Hello World!",10,0
                    hello_size = $-hello_msg


                    It comiles with



                    fasm hello.asm hello





                    share|improve this answer



























                      8














                      There is also FASM for Linux.



                      format ELF executable

                      segment readable executable

                      start:
                      mov eax, 4
                      mov ebx, 1
                      mov ecx, hello_msg
                      mov edx, hello_size
                      int 80h

                      mov eax, 1
                      mov ebx, 0
                      int 80h

                      segment readable writeable

                      hello_msg db "Hello World!",10,0
                      hello_size = $-hello_msg


                      It comiles with



                      fasm hello.asm hello





                      share|improve this answer

























                        8












                        8








                        8







                        There is also FASM for Linux.



                        format ELF executable

                        segment readable executable

                        start:
                        mov eax, 4
                        mov ebx, 1
                        mov ecx, hello_msg
                        mov edx, hello_size
                        int 80h

                        mov eax, 1
                        mov ebx, 0
                        int 80h

                        segment readable writeable

                        hello_msg db "Hello World!",10,0
                        hello_size = $-hello_msg


                        It comiles with



                        fasm hello.asm hello





                        share|improve this answer













                        There is also FASM for Linux.



                        format ELF executable

                        segment readable executable

                        start:
                        mov eax, 4
                        mov ebx, 1
                        mov ecx, hello_msg
                        mov edx, hello_size
                        int 80h

                        mov eax, 1
                        mov ebx, 0
                        int 80h

                        segment readable writeable

                        hello_msg db "Hello World!",10,0
                        hello_size = $-hello_msg


                        It comiles with



                        fasm hello.asm hello






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 18 '10 at 7:39









                        Artur ArtamonovArtur Artamonov

                        912




                        912





















                            7














                            My suggestion would be to get the book Programming From Ground Up:



                            http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf



                            That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.






                            share|improve this answer





























                              7














                              My suggestion would be to get the book Programming From Ground Up:



                              http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf



                              That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.






                              share|improve this answer



























                                7












                                7








                                7







                                My suggestion would be to get the book Programming From Ground Up:



                                http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf



                                That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.






                                share|improve this answer















                                My suggestion would be to get the book Programming From Ground Up:



                                http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf



                                That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jun 17 '16 at 11:10









                                Pabru

                                1737




                                1737










                                answered Sep 29 '10 at 13:47









                                gilligangilligan

                                433315




                                433315





















                                    4














                                    The assembler(GNU) is as(1)






                                    share|improve this answer



























                                      4














                                      The assembler(GNU) is as(1)






                                      share|improve this answer

























                                        4












                                        4








                                        4







                                        The assembler(GNU) is as(1)






                                        share|improve this answer













                                        The assembler(GNU) is as(1)







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jul 23 '10 at 2:17









                                        RecursionRecursion

                                        1,37262646




                                        1,37262646





















                                            3














                                            3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.



                                            http://www.tortall.net/projects/yasm/






                                            share|improve this answer



























                                              3














                                              3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.



                                              http://www.tortall.net/projects/yasm/






                                              share|improve this answer

























                                                3












                                                3








                                                3







                                                3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.



                                                http://www.tortall.net/projects/yasm/






                                                share|improve this answer













                                                3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.



                                                http://www.tortall.net/projects/yasm/







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Oct 21 '10 at 10:41









                                                plan9assemblerplan9assembler

                                                2,6801913




                                                2,6801913





















                                                    0














                                                    For Ubuntu 18.04 installnasm . Open the terminal and type:



                                                    sudo apt install as31 nasm



                                                    nasm docs



                                                    For compiling and running:



                                                    nasm -f elf64 example.asm # assemble the program 
                                                    ld -s -o example example.o # link the object file nasm produced into an executable file
                                                    ./example # example is an executable file





                                                    share|improve this answer

























                                                    • as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                      – Peter Cordes
                                                      Nov 14 '18 at 21:50















                                                    0














                                                    For Ubuntu 18.04 installnasm . Open the terminal and type:



                                                    sudo apt install as31 nasm



                                                    nasm docs



                                                    For compiling and running:



                                                    nasm -f elf64 example.asm # assemble the program 
                                                    ld -s -o example example.o # link the object file nasm produced into an executable file
                                                    ./example # example is an executable file





                                                    share|improve this answer

























                                                    • as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                      – Peter Cordes
                                                      Nov 14 '18 at 21:50













                                                    0












                                                    0








                                                    0







                                                    For Ubuntu 18.04 installnasm . Open the terminal and type:



                                                    sudo apt install as31 nasm



                                                    nasm docs



                                                    For compiling and running:



                                                    nasm -f elf64 example.asm # assemble the program 
                                                    ld -s -o example example.o # link the object file nasm produced into an executable file
                                                    ./example # example is an executable file





                                                    share|improve this answer















                                                    For Ubuntu 18.04 installnasm . Open the terminal and type:



                                                    sudo apt install as31 nasm



                                                    nasm docs



                                                    For compiling and running:



                                                    nasm -f elf64 example.asm # assemble the program 
                                                    ld -s -o example example.o # link the object file nasm produced into an executable file
                                                    ./example # example is an executable file






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 14 '18 at 22:09

























                                                    answered Nov 14 '18 at 21:46









                                                    Geancarlo MurilloGeancarlo Murillo

                                                    11819




                                                    11819












                                                    • as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                      – Peter Cordes
                                                      Nov 14 '18 at 21:50

















                                                    • as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                      – Peter Cordes
                                                      Nov 14 '18 at 21:50
















                                                    as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                    – Peter Cordes
                                                    Nov 14 '18 at 21:50





                                                    as31 is an assembler for 8051 code. Linux doesn't run on 8051 microcontrollers, so you can't link and then run anything you assemble with it right on your Linux machine (which is what this question was about).

                                                    – Peter Cordes
                                                    Nov 14 '18 at 21:50

















                                                    draft saved

                                                    draft discarded
















































                                                    Thanks for contributing an answer to Stack Overflow!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid


                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.

                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3314919%2fcompile-run-assembler-in-linux%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    這個網誌中的熱門文章

                                                    Barbados

                                                    How to read a connectionString WITH PROVIDER in .NET Core?

                                                    Node.js Script on GitHub Pages or Amazon S3