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, %
r10,r10d,r10w,r10b,r11,r11d,r11w,r11b, %
r12,r12d,r12w,r12b,r13,r13d,r13w,r13b, %
r14,r14d,r14w,r14b,r15,r15d,r15w,r15b}} % 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:
(I've just added the instructions listed here and only some of the registers, you can easily add any more that you use.)
Here is a simple example to get you started.
\documentclass{article}
\usepackage{listings}
\lstset{language=R,literate={<-}{{$\gets$}}1}
\begin{document}
\begin{lstlisting}
a <- c(1,2,3)
b <- data.frame(this=a,that=c(3,4,5))
\end{lstlisting}
\end{document}
The "literate" part gives you nicer assignment arrows, which is useful if you use "<-" for assignment, and there is a great deal more customisation that you can do. For full details you should read the fine manual on CTAN.
Best Answer
If you don't select a language dialect in square brackets,
listings
falls back to the default dialect and if there is none to the empty dialect.The language
Assembler
is defined without an empty dialect and has no default dialect, so you need to explicitly specify a dialect when you select the language. The available dialects ofAssembler
arex86masm
andMotorola68k
.Remember that LaTeX usually only accepts nested square brackets when you hide the inner brackets in curly braces.