I’m interesting in compile a 32bit assembly code using a 64bit machine.
This is the 32 bit code:
.global factorial
factorial:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
pushl %esi
pushl %ebx
movl $1,-4(%ebp)
movl $2,%esi
for:
cmpl 8(%ebp), %esi
jg endfor
movl -4(%ebp), %ebx
imull %esi, %ebx
movl %ebx, -4(%ebp)
incl %esi
jmp for
endfor:
movl -4(%ebp), %eax
popl %ebx
popl %esi
movl %ebp, %esp
popl %ebp
ret
I’m building:
> gcc test32.s -m32 -o test32
But I’m obtaining:
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib32/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
know someone who’s going? Thanks in advance!
You are trying to compile and link to an executable. For that to work, you need a
mainfunction that contains the programs start function.All you have is a single mathematical function, without any way to define inputs and outputs.