34

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

Jens
  • 69,818
  • 15
  • 125
  • 179
Pwn
  • 3,387
  • 11
  • 38
  • 42
  • 9
    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 Aug 21 '15 at 19:04
  • It will be very nice if you restore images. – Tacet Mar 18 '17 at 14:43

4 Answers4

57

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.

Community
  • 1
  • 1
Andy
  • 3,794
  • 24
  • 28
  • If you want to find the mentioned `:help syntax` excerpt for yourself, it's around line 821 (use `:set number`) – spicy.dll Jun 13 '19 at 02: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

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Shirkrin
  • 3,993
  • 1
  • 29
  • 35
  • 1
    O_o loving those colors! Mind sharing what they are? – Cole Tobin Nov 27 '12 at 00:45
  • 2
    The scheme is called 'lettuce': http://www.vim.org/scripts/script.php?script_id=1975 – Shirkrin Nov 27 '12 at 06:43
  • I had to update the screenshot - the colors now are "base16-bright" (https://github.com/chriskempson/base16-vim.git) – Shirkrin May 24 '15 at 18:22
  • Aw, if only I were smart enough to google this first... Would've saved me a lot of trouble a few years ago. Anyway, I made one for Sublime Text that I ported over to vim: (https://github.com/calculuswhiz/vim-GAS-x86_64-highlighter) I've tested it fairly extensively, and I think it's a decent alternative. – General Grievance Jan 31 '17 at 03:51
  • I was going the other way and learned to hate sublimes syntax engine ^^ – Shirkrin Jan 31 '17 at 12:46
4

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
cassepipe
  • 371
  • 6
  • 16
  • 3
    Is `nasm` highlighting actually good for `.S` / `.s` GNU-assembler files? They use different comment characters. – Peter Cordes May 06 '21 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 `Make`does not seem to be able to automatically make `.o` from `.asm` files. – cassepipe May 06 '21 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). – Peter Cordes May 06 '21 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 May 06 '21 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](https://stackoverflow.com/a/36901649/224132). 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. – Peter Cordes May 06 '21 at 21:38
2

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

Sprite
  • 3,222
  • 1
  • 12
  • 29
Shadorain
  • 21
  • 4