Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>RISC-V Assembly Syntax HighlightingNew to Visual Studio Code? Get it now.
RISC-V Assembly Syntax Highlighting

RISC-V Assembly Syntax Highlighting

David E. Grayson

|
2 installs
| (0) | Free
Control flow-aware syntax highlighting for RISC-V assembly
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

riscv-asm-vscode

Visual Studio code extension that provides syntax highlighting for RISC-V assembly.

This extension highlights instructions defined in the RISC-V Instruction Set Manual Volume I, Chapters 1 to 30.

Control flow-aware syntax highlighting

To make it easier to quickly understand the structure of RISC-V assembly programs, this extension applies the scope keyword.control to assembly instructions that can jump to another part of the program, as well as prepocessor directives. This is the same scope applied to keywords like if and else in highlighters for higher-level languages. Non-control instructions get the scope keyword.mnemonic. With the default VS Code color theme, this makes the control instructions pop out nicely:

{code}

Several color themes do not define distinct colors for keyword.control and keyword.mnemonic. If you want control flow-aware highlighting for those color schemes, or you just want to change the color of the control instructions, you should define your own styling rule: press Ctrl+Shift+P, select "Preferences: Open User Settings (JSON)", then add something like this to the top-level object:

    "textMateRules": [
      {
        "scope": "keyword.control",
        "settings": {
          "foreground": "#C586C0"
        }
      }
    ]

Additionally, you can apply special coloring to a subset of the control keywords using the following scopes:

  • keyword.control.conditional: Conditional jump instructions like bltu
  • keyword.control.directive: Prepocessor directives like #if and #include
  • keyword.control.call: Instructions designed to call other functions like call, tail, and jal

Here is what the Monokai theme could look like with four extra rules to give each type of control keyword a different color:

{code}

A quick intro to Visual Studio Code syntax highlighting

This extension does not actually define any colors.

In the file riscvasm.tmLanguage.json, this extension defines several regular expressions that match pieces of a program called "tokens", and corresponding strings known as "scopes" to apply to those tokens.

A scope is just a string like keyword.control.conditional that is used to style the token. To see the tokens and scopes of any part of a VS Code document, put your cursor inside or before that part, press Ctrl+Shift+P, then run "Developer: Inspect Editor Tokens and Scopes".

The color scheme you are using has many rules that specify the color/style of each scope. To add your own styling rules, press Ctrl+Shift+P, select "Preferences: Open User Settings (JSON)", then add something like this to the top-level object:

    "textMateRules": [
      {
        "scope": "keyword.control.conditional",
        "settings": {
          "foreground": "#957ac4"
        }
      }
    ]

When coloring a token with scope "AA.BB.CC", VS Code applies any rules with scope "AA", "AA.BB", or "AA.BB.CC". Attributes in the rules with more-specific (longer) scopes override conflicting attributes from less-specific rules.

For more info, see the official Syntax Highlight Guide.

Tips for developing this extension

Install NodeJS. For exmaple, on MSYS2, run:

pacman -S $MINGW_PACKAGE_PREFIX-nodejs

Open this repository as the workspace. Run Ctrl+F5 to open a new VS Code window with the extension loaded from the files in the workspace. In that new window, open a RISC-V assembly file, and make sure it says "RISC-V Assembly" in the lower right corner of the window where the language is shown.

Publishing a new version

See Publishing Extensions.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft