Take the 2-minute tour ×
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 writing a paper with a lot of x86-64 code listings in it. Unfortunately, the listings package itself does not have support for x86-64 instructions and register names (which are just named different than the 32 bit counterparts).

Does anyone have the code to configure the package to support that?

share|improve this question
    
The package itself provides the possibility of define new languages. Thus you just have to follow the rules explained in the documentation. –  Claudio Fiandrino Apr 12 '12 at 11:54
add comment

1 Answer

up vote 8 down vote accepted

The documentation for listings describes the \lstdefinelanguage macro, which can be used to define new languages as extensions of others.

\documentclass{article}

\usepackage{listings}

\lstdefinelanguage
   [x64]{Assembler}     % add a "x64" dialect of Assembler
   [x86masm]{Assembler} % based on the "x86masm" dialect
   % with these extra keywords:
   {morekeywords={CDQE,CQO,CMPSQ,CMPXCHG16B,JRCXZ,LODSQ,MOVSXD, %
                  POPFQ,PUSHFQ,SCASQ,STOSQ,IRETQ,RDTSCP,SWAPGS, %
                  rax,rdx,rcx,rbx,rsi,rdi,rsp,rbp, %
                  r8,r8d,r8w,r8b,r9,r9d,r9w,r9b}} % etc.

\lstset{language=[x64]Assembler}

\begin{document}
\begin{lstlisting}
  cdqe 1, r8
  push 1
  add rsp, 4
  push 1
\end{lstlisting}
\end{document}

Which looks a little like:

output of the above LaTeX

(I've just added the instructions listed here and only some of the registers, you can easily add any more that you use.)

share|improve this answer
add 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.