3

I am trying to make my own syntax highlighting for ARM assembly by defining a language as follows:

\lstdefinelanguage{ASM}{
    morekeywords={b, ble, blt, bne, 
        ldr, str, 
        r0, r1, r2, r3, r4, r5, r6, r7, rr8, r9, r10, r11, r12
        sp  },
    sensitive=false, % keywords are not case-sensitive
    morecomment=[l]{//}, % l is for line comment
    morecomment=[s]{/*}{*/}, % s is for start and end delimiter
    morestring=[b]" % defines that strings are enclosed in double quotes
} % 

However when I do:

\lstset{language=ASM}
\begin{lstlisting}[style = ASM]
    .section .init
    .global _start

    _start:
        ldr sp, =8000
        b kernel_main
\end{lstlisting}

I am told "undefined control sequence ldr" and "undefined control sequence b". Removing them from the keywords solves the issue but then I have no syntax highlighting. What did I do wrong?

1
  • Welcome to TeX.SX. Rather than posting code snippets it is better to post a full minimal working example that begins with as \documentclass command,l includes all relevant packages and \begin{document}...\end{document}. In this instance, it won't compile but it should be as small as possible to demonstrate your problem.
    – user30471
    May 26, 2017 at 8:25

1 Answer 1

1

Looking at what you have, you seem to be missing a comma at the end of the line ...r11, r12 and your lstlisting environment should probably be \begin{lstlisting}[language = ASM], rather than using style. With these two fixes your code produces:

enter image description here

Here is the full minimal working example:

\documentclass{article}
\usepackage{listings}

\lstdefinelanguage{ASM}{
    morekeywords={b, ble, blt, bne,
        ldr, str,
        r0, r1, r2, r3, r4, r5, r6, r7, rr8, r9, r10, r11, r12,
        sp  },
    sensitive=false, % keywords are not case-sensitive
    morecomment=[l]{//}, % l is for line comment
    morecomment=[s]{/*}{*/}, % s is for start and end delimiter
    morestring=[b]" % defines that strings are enclosed in double quotes
} %

\begin{document}

\begin{lstlisting}[language = ASM]
    .section .init
    .global _start

    _start:
        ldr sp, =8000
        b kernel_main
\end{lstlisting}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .