c and IA32 assembly languauge

What is to key to translating code written in C into assembly code? I have tell what the funcation is doing and what arguments passed. Where do I start I do not have mystery.c I am onyl given this. where/how do I start

.file "mystery.c"
.text
.globl mystery
.type mystery, @function
mystery:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $0, -8(%ebp)
movl $0, -4(%ebp)
jmp .L2
.L3:
movl -4(%ebp), %eax
sall $2, %eax
addl 8(%ebp), %eax
movl (%eax), %eax
addl %eax, -8(%ebp)
addl $1, -4(%ebp)
.L2:
movl -4(%ebp), %eax
cmpl 12(%ebp), %eax
jl .L3
movl -8(%ebp), %eax
leave
ret
Last edited on
It looks like you need to understand the assembly language. A starting point would be a helpful tutorial and a copy of the instruction set.

C/C++ compilers are often equiped to generate the assembly language along with the object file. You might want to look at that to get a feel for translated C/C++ code.
where would I find a good tutorial on assembly language? I have only find college course summaries of what is taught. My professor does not want us to have the instruction set.
Have you tried Google "assembly language tutorial intel"?
Here's a quick translation into pseudocode. I still don't know what it does though!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
LocalVar1 = 0
LocalVar2 = 0
JUMP L2
L3:
 A = LocalVar2
 A <<= 2                    // Arithmetic shift left
 A += Param1
 LocalVar1 += *A
 LocalVar2 += 1
L2:
 JUMP L3 if LocalVar2 < Param2
A = LocalVar1               // Put return value in A.
LEAVE                       // Clean up stack.
RETURN


Edit: Now that I look at it, though, I guess it's summing an array of integers perhaps?
Last edited on
yup.
Topic archived. No new replies allowed.