36

The default assembly syntax file didn't work well and searching the web about gas assembly I found nothing about a gas (AT&T) syntax file for vim. Has anyone found this? I can't write my own syntax file.

http://img168.imageshack.us/img168/46/nasm.png ft=nasm

http://img160.imageshack.us/img160/5857/asm.png ft=asm(default)

http://img164.imageshack.us/img164/8476/tasm.png ft=tasm

2
  • 10
    The images are gone. Can you see if you can salvage the info? If you still have the images uploading them to SE's own imgur account would prevent this from happening again.
    – rene
    Commented Aug 21, 2015 at 19:04
  • It will be very nice if you restore images.
    – Tacet
    Commented Mar 18, 2017 at 14:43

4 Answers 4

60
+100

This may get you started. Is that more like what you're looking for?

Just had a quick search - it looks like there are a few different sorts of assembly syntax highlighting built in. Which one are you using?

Copy-pasted from :help syntax

Currently these syntax
files are included:
    asm     GNU assembly (the default)
    asm68k      Motorola 680x0 assembly
    asmh8300    Hitachi H-8300 version of GNU assembly
    ia64        Intel Itanium 64
 fasm Flat assemlby http://flatassembler.net
    masm        Microsoft assembly (probably works for any 80x86)
    nasm        Netwide assembly
    tasm        Turbo Assembly (with opcodes 80x86 up to Pentium, and
            MMX)
    pic     PIC assembly (currently for PIC16F84)

The most flexible is to add a line in your assembly file containing:
    :asmsyntax=nasm
Replace "nasm" with the name of the real assembly syntax.  This line must be
one of the first five lines in the file.

This additional syntax script is from vim.org

It looks like your screenshot is using the default asm filetype. Try

:set ft=nasm

and you should get some colour changes as per these screenshots.

ft=nasm

From your screenshots above I've made a couple of quick modifications to the fasm vim syntax and called it gasm. It can be found here on pastebin.

Copy and paste that into your personal .vim/syntax or vimfiles/syntax directory and call it gasm.vim Then in your assembly file :set ft=gasm

This vim script relies on comments being of the form % comment with the space included. You can see this (or change it if you wish) on line 116 of the script.

Please note: Don't copy the line numbers.

1
  • If you want to find the mentioned :help syntax excerpt for yourself, it's around line 821 (use :set number)
    – spicy.dll
    Commented Jun 13, 2019 at 2:39
29

I started to write a complete GNU as syntax from scratch.

The syntax file is available from vim.org: GNU as syntax for X86
As well as directly on GitHub: GNU as syntax for X86

In addition to the basic instructions it will recognize the following extended Intel / AMD instructions:

  • X86 common instruction set (8086 - 686)
  • Katmai Streaming SIMD instructions (SSE -- a.k.a. KNI, XMM, MMX2)
  • Introduced in Deschutes but necessary for SSE support
  • XSAVE group (AVX and extended state)
  • Generic memory operations
  • New MMX instructions introduced in Katmai
  • AMD Enhanced 3DNow! (Athlon) instructions
  • Willamette SSE2 Cacheability Instructions
  • Willamette MMX instructions (SSE2 SIMD Integer Instructions)
  • Willamette Streaming SIMD instructions (SSE2)
  • Prescott New Instructions (SSE3)
  • VMX Instructions
  • Extended Page Tables VMX instructions
  • Tejas New Instructions (SSSE3)
  • AMD SSE4A
  • New instructions in Barcelona
  • Penryn New Instructions (SSE4.1)
  • Nehalem New Instructions (SSE4.2)
  • AMD SSE5 instructions
  • Intel SMX
  • Geode (Cyrix) 3DNow! additions
  • Intel AES instructions
  • Intel AVX AES instructions
  • Intel AVX instructions
  • Intel Carry-Less Multiplication instructions (CLMUL)
  • Intel AVX Carry-Less Multiplication instructions (CLMUL)
  • Intel Fused Multiply-Add instructions (FMA)
  • VIA (Centaur) security instructions
  • AMD XOP, FMA4 and CVT16 instructions (SSE5)
  • Systematic names for the hinting nop instructions

Here is how it looks like:

alt text

5
7

Putting this line in your .vimrc will set you up with the intel syntax whenever you open an .asm file :

autocmd BufNew,BufRead *.asm set ft=nasm
5
  • 3
    Is nasm highlighting actually good for .S / .s GNU-assembler files? They use different comment characters. Commented May 6, 2021 at 15:23
  • I think you are right about .S since it calls for the GNU preprocessor from what I understand and so are intended for gcc. You are also right about .s as it the format that calling gcc -S will output but in my case I'd keep it in order to benefit from Make implicit rules for simple programs as Makedoes not seem to be able to automatically make .o from .asm files.
    – cassepipe
    Commented May 6, 2021 at 19:37
  • 1
    Make's built-in rule for .s files runs gcc on them, which will not work if they're written in NASM syntax. GNU assembler uses entirely different directives (and defaults to AT&T syntax). Commented May 6, 2021 at 19:50
  • @PeterCordes You are right but in my case I can easily use Make with AS = nasm and ASFLAGS = -f elf64 and it works well. You seem to know more than I do so please feel free to edit my answer accordingly. The reason I added this answer is because this the easy/lazy permanent fix I wish I had read to quickly get that pb out of the way. Especially because the ALE linter was most unhappy with my intel syntax. Do you suggest a better/more conventional way to go about it? I'm all hears.
    – cassepipe
    Commented May 6, 2021 at 21:23
  • 1
    If you have to actually write a Makefile, you might as well use a pattern-rule for making a .o from a .asm file. When I'm messing around with asm, it's usually for a single-file program to test something out, so I just run a script I wrote myself, asm-link foo.asm (included in this answer. No need to bother with a Makefile. (And no need to break how your vim setup handles normal .s / .S files that do have Unix-assembler contents.) So I'd simply remove the *.s line, keeping the .asm line. Commented May 6, 2021 at 21:38
3

Vim/Nvim if unable to detect specific filetype can be told what it is with an actual macro in the file itself instead of having to run the :set ft=nasm command each time you open the file.

To do this, figure out what the comment syntax of the file type is and add a line like this to the end of your file: (e.g. for NASM)

; vim:ft=nasm

This image shows the syntax highlighting in action as well as how the file looks with the line added.

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.