Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the x86masm dialect of Assembler and register names are emphasized even when they occur inside of a label or a hexadecimal number. For example, dh is register, but 0dh is a number, yet the dh part of it is emphasized. I haven't had this problem in listings with any other languages, so I'm assuming it's a problem with the language definition. Is there simple way to redefine the language so that this doesn't happen?

\documentclass[12pt]{article}
\usepackage{courier, listings}

\lstset{
  language={[x86masm]Assembler},
  basicstyle=\ttfamily\small,
  frame=single
}

\begin{document}
\begin{lstlisting}
cmp al, 0dh ; dh = register, 0dh = number
je somewhere
\end{lstlisting}

\end{document}
share|improve this question

1 Answer

use deletekeywords=.... However, you should use another monotypefont like beramono. Courier is not a good looking mono font.

\documentclass[12pt]{article}
\usepackage{courier, listings}

\lstset{
  language={[x86masm]Assembler},
  basicstyle=\ttfamily\small,
  frame=single,
  deletekeywords={dh}
}

\begin{document}
\begin{lstlisting}
cmp al, 0dh ; dh = register, 0dh = number
je somewhere
\end{lstlisting}

\end{document}
share|improve this answer
I might still use the dh register somewhere else, and I'd want it emphasized there. Also, this happens with a lot of other registers (bh, ah, ch), and labels are even more likely to have mnemonics in them, so I might as well remove all highlighting if I'm gonna do it this way. – Adrian Sep 14 '11 at 14:26
1  
@Herbert: I think the problem is that the OP wants the register dh highlighted, but does not want it highlighted in the number 0dh. Seems that to get a complete general solution, the package would be required to parse the actual language to do that as opposed to just match keywords. – Peter Grill Sep 14 '11 at 16:15
1  
I did some more tests, and this is a listings problem, not just a problem with the language definition. It only happens with literals starting with digits, ending in a keyword, and containing no other letters. This problem is much more likely to occur in assembly than in other languages because of the short mnemonic names and ubiquity of hexadecimal numbers. – Adrian Sep 14 '11 at 16:40
2  
Okay, I was able to solve this by turning on case sensitivity and making all hexadecimal digits uppercase. – Adrian Sep 14 '11 at 16:50
1  
@Adrian: Your last two comments might be worth to be given as an answer: They give some more hints about the root of the problem and provide a reasonable workaround. (Note that it is perfectly acceptable to answer your own questions, other members might profit from your solution!) – Daniel Sep 14 '11 at 19:25
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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