我正在尝试制作以下 x86 汇编语言列表样式:
但我无法做到。我的清单代码如下:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\lstdefinestyle{customasm}{
belowcaptionskip=1\baselineskip,
frame=single,
frameround=tttt,
xleftmargin=\parindent,
language=[x86masm]Assembler,
basicstyle=\footnotesize\ttfamily,
commentstyle=\itshape\color{green!60!black},
keywordstyle=\color{blue!80!black},
identifierstyle=\color{red!80!black},
tabsize=4,
numbers=left,
numbersep=8pt,
stepnumber=1,
numberstyle=\tiny\color{gray},
columns = fullflexible,
}
\begin{document}
\section*{x86 Listing}
\begin{lstlisting}[style=customasm, caption={x86 Code}, label=x86code]
.MODEL SMALL
.STACK 100H
.CODE
MOV AX, 0x3C
MOV BX, 0000000000001010B
ADD AX, BX
MOV BX, 14
SUB AX, BX
MOV AH, 04CH
INT 21H
\end{lstlisting}
\end{document}
答案1
也许使用minted
包而不是listings
会是一个解决方案?nasm
词法分析器产生的输出与您的示例非常相似。
\documentclass{article}
\usepackage{caption}
\usepackage[newfloat]{minted}
\captionsetup[listing]{position=top}
\begin{document}
\section*{x86 Listing}
\begin{listing}[h]
\caption{x86 Code}
\begin{minted}[linenos,frame=single]{nasm}
.MODEL SMALL
.STACK 100H
.CODE
MOV AX, 0x3C
MOV BX, 0000000000001010B
ADD AX, BX
MOV BX, 14
SUB AX, BX
MOV AH, 04CH
INT 21H
\end{minted}
\end{listing}
\end{document}
结果: