23 thoughts on “Linux x64 Assembly Tutorial 1: Getting a Value from NASM into G++

  1. What if I don't have the rights to install the NASM, is there a way to download it and configure somehow?

    And also all my institute computers are Arch based, so I can't download it using apt-get, I got to use pacman, and I always get confused!

    You wouldn't probably read this, but if so, help me!

  2. you actually can use the intel syntax in gcc/g++/mingw inline assembly if you do it like this:

    "mov eax, 0;"

  3. Great video, I'm having so much fun with this assembler stuff!

    Anyone else coming from MacOS as I am, there are a few tweaks that I needed to make for this to work.

    First of all, update nasm, so that it includes support for macho64, on MacOS 10.10

    $ brew install nasm
    # Relog your terminal, (create a new session)
    $ nasm -v
    => NASM version 2.11.06 compiled on Nov  4 2014

    Mac do things differently to linux, labels are prefixed with underscores, so this means you'll need to change GetDataFromASM to _GetDataFromASM in your asm file, both in the global declaration and in its implementation:

    global _GetValueFromASM
    segment .data
    segment .text
      mov rax, 51773

    And finally, because your on Mac, you'll be telling nasm to use file format of macho64 (which is why you updated nasm earler):

    runme: main.cpp main.o
      g++ main.cpp main.o -o runme

    main.o: main.asm
      nasm -f macho64 main.asm -o main.o

    Notice nasm -f macho64 instead of elf64. Disregard the file name changes, I used main.asm instead of asm.asm as in the video.

  4. Your first step should be: sudo apt-get install build-essential
    On Ubuntu system this install all that is needed to build and compile projects.

  5. I think G++ complies to your current system architecture by default. Your probably using the x86_64 version of Ubuntu, and if you were using the 32 bit version g++ would default to 32 bit binaries.

  6. I really like how you refer to stuff by their proper names, rather than their acronyms.

    "That's going to have the netwide assembler assemble our assembly file…"
    Best line in the video.

  7. "If you're using a different distro, a different flavor of Linux, then uh… yeah, good luck; I hope you can figure it out."

    Thanks man.

  8. I'm sure it's got something to do with the fact I'm trying this on OS X 10.8, instead of ubuntu.. the GetValueFromASM() always ends up returning 0 (not a bad thing I guess) — but it's not the value I was trying for =_=* good thing I've got a virtual machine handy to follow along I guess lol

  9. This stuff is pure Gold! Thank you very much for sharing your knowledge, especially on an opensource system like Linux, vs the slightly more difficult to obtain and configure VisualStudio 😀 cheers

Leave a Reply

Your email address will not be published. Required fields are marked *