tags:

views:

71

answers:

2

hello, can somebody please explain is it possible to convert this snippet of the code to assembly of pdp11?

movq    %rdi, -8(%rbp)
    movl    %esi, -12(%rbp)
    movl    %edx, -16(%rbp)
    movl    -16(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdi
    movq    -8(%rbp), %r8
    movl    -12(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rcx
    movq    -8(%rbp), %rsi
    movl    -16(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdx
    movq    -8(%rbp), %rax
    movl    (%rdx,%rax), %eax
    addl    (%rcx,%rsi), %eax
    movl    %eax, (%rdi,%r8)
    movl    -12(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdi
    movq    -8(%rbp), %r8
    movl    -16(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rcx
    movq    -8(%rbp), %rsi
    movl    -12(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdx
    movq    -8(%rbp), %rax
    movl    (%rdx,%rax), %edx
    movl    (%rcx,%rsi), %eax
    subl    %edx, %eax
    movl    %eax, (%rdi,%r8)
    movl    -16(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdi
    movq    -8(%rbp), %r8
    movl    -16(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rcx
    movq    -8(%rbp), %rsi
    movl    -12(%rbp), %eax
    cltq
    leaq    0(,%rax,4), %rdx
    movq    -8(%rbp), %rax
    movl    (%rdx,%rax), %edx
    movl    (%rcx,%rsi), %eax
    subl    %edx, %eax
    movl    %eax, (%rdi,%r8)
    leave
    ret

it is only small part of all code that I have... also I has C code of the same program, I found that using gcc -S flag, I can get assembly code but can I convert it to the code of pdp11?

+3  A: 

If I get you right you just want to run a C program. If that's right, you can see here that PDP-11 is supported by GCC 4.3.

http://en.wikipedia.org/wiki/GNU_Compiler_Collection#Architectures

Get GCC 4.3 sources, learn how to build a cross-compiler and your problem is solved.

No need to translate amd64 assembly to PDP-11

jbcreix
can You explain please about cross-compiler, I'm not sure that I understood it
lego69
@lego69 A Cross-compiler is a compiler that runs on a different architecture than the code it will compile. If you search for gcc building a cross-compiler you will get all you need. In unix you would do ./configure --target=pdp11 or something of the sort in GCC source directory and then make. If you want a binary instead of just assembly output you will also need a cross-* version of `binutils` also made by GNU. If you are in Windows it might be more difficult, I recommend getting cygwin as the easiest way out because you can use the same commands you will find on the web.
jbcreix
A: 

Given that the PDP-11 is a 16-bit processor, you'd be much better off running your C through a compiler that will produce 16-bit code instead of the 64-bit code you've posted. It's probably easier to translate from C source code to assembly (by hand) than from 64-bit Intel assembly to PDP-11 assembly by hand.

You might also want to look at Dennis Ritchie's primeval C compilers page. As I recall, he has a link to somebody who's gotten one or two of these old compilers to compile and run in modern C. Its targets the PDP-11 (though the source it accepts is NOT modern C). You might also look at the work that's been done on targeting the PDP-11 with lcc. I believe there's a complete, working implementation. Though I have no idea whether anybody has tested it recently, somewhere in the pcc archives, there should probably still be an ancient PDP-11 code generator (that was heavily used at one time).

Jerry Coffin
@Jerroy Coffin: sorry but what about gcc, it will be easier? or not?
lego69
@lego69: maybe. Until you try, there probably is no other answer (different people clearly find different things easier).
Jerry Coffin
@Jerroy Coffin: can I do just something like this gcc -pdp-11 -S foo.c?
lego69
@lego69, no, but you can do something like pdp11-gcc -S foo.c if you use a cross-compiler.
jbcreix