TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some C code that I want to insert in a LaTeX document using a listing. I also want to display its translation to assembly code. I don't know how to display those two kind of codes in a multicolumn view, so to give the reader the possibility to make a quick comparison between C code and assembly code. I don't need to have the lines of C aligned with their correspondent assembly instructions since I think this is not going to be easy to do. What I need is just to show the two codes side by side. Can you help me?


share|improve this question
up vote 7 down vote accepted

The code can be displayed using the listings package. The side by side effect I would do using two minipages as shown below. In general you have to be careful because the listings are verbatim material and don't work inside the arguments of other macros. (Using saveboxes helps here)






   int function test(int a) {
         return a;
       goto SOMEWHERE




share|improve this answer

You may try parcolumns package.

See also other question: Of parallel texts, lists and display equations.


%% far from complete list of gasm-specific keywords and instructions in AT&T syntax
\texttt{gcc} on \texttt{text.c} file (left side) [\texttt{gcc -S -Os text.c}] gives following assembler code (right side):
#include <stdio.h>

int main(int argc, char *argv[])
    int t;

    if (argc < 2) {
        fprintf(stderr, "Not enough arguments!\n");
        return 1;

    t = atoi(argv[1]);
    printf("%d^2 = %d\n", t, t * t);

    return 0;
    .file   "test.c"
    .section    .rodata.str1.1,"aMS",@progbits,1
    .string "Not enough arguments!\n"
    .string "%d^2 = %d\n"
.globl main
    .type   main, @function
    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    decl    %edi
    jg  .L2
    movq    stderr(%rip), %rsi
    movl    $.LC0, %edi
    call    fputs
    movl    $1, %eax
    jmp .L3
    movq    8(%rsi), %rdi
    xorl    %eax, %eax
    call    atoi
    movl    %eax, %edx
    movl    %eax, %esi
    movl    $.LC1, %edi
    imull   %eax, %edx
    xorl    %eax, %eax
    call    printf
    xorl    %eax, %eax
    popq    %rdx
    .size   main, .-main
    .ident  "GCC: (Debian 4.4.5-8) 4.4.5"
    .section    .note.GNU-stack,"",@progbits

enter image description here

share|improve this answer
The code you provided is very complete, thanks. – Raffo Jul 14 '11 at 10:42

Your Answer


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.