0

I am new to NASM especially in ubuntu64 using vim.

Currently, when I write assembly code with vim, it does not recognize the labels and does not auto-tab, maybe it's because it's not supposed to do that (it's not conventional) although I would be pretty happy if it could do that here too.. (like auto tab with python on vim)

Vim assembly code

When I press enter it goes back to the beginning of the line, where the red arrow points.

Secondly, when I need to "compile" (I don't know if it's the right term here, maybe "assemble") the code, I need to write both:

nasm -f elf64 hello.asm

and

ld -s -o hello hello.o

Is there a shorter way of doing so? maybe both at the same time, an easy 2-in-1 command?

CodeCop
  • 1
  • 2
  • 15
  • 37
  • Can you simply put both on one line as a compound command like `nasm ... && ld ...`? If Vim uses a shell to run commands, the shell will parse the && – Peter Cordes Jan 13 '21 at 07:26

1 Answers1

1

Create a shell script: make a new text file and name it "assemble.sh" or whatever you want, then type in the following two lines.

nasm -f elf64 "$1.asm"  &&
 ld -o "$1" "$1.o"              # only try ld if assembling succeeded

You might want to add other options to get NASM to add more or less debugging info, depending on how you debug. ld -s would strip the binary, but you generally don't want that for debugging.

Then you have to make it executable with a "chmod +x assemble.sh"

so then you can ./assemble.sh hello. Or put it in your ~/bin directory you it's in your PATH.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Arthur Kalliokoski
  • 1,627
  • 12
  • 12
  • 1
    I have a script called `asm-link` that does basically that, supporting a few options like `-m32`, and `-d` to disassemble the output. It takes `foo.asm` as an input so tab-completion fully works, and strips the suffix to find the base name. It's part of my answer on [Assembling 32-bit binaries on a 64-bit system (GNU toolchain)](https://stackoverflow.com/a/36901649) but probably it would be a better fit here on this new Q&A. – Peter Cordes Jan 13 '21 at 07:20