Strange behaviour, program segfaults
André Reffhaug
areffhaug at gmail.com
Mon Apr 10 02:53:54 PDT 2006
Hey all. I have no great experience with Yasm, but I enjoy using it,
and I think it's a great effort.
I have been experimenting a little bit with it, and I've come across
something strange. The following code, when compiled with "yasm -p gas
-f elf file.s -o file.o" and "ld file.o -o file" causes a segmentation
fault. When compiling with "as" it runs fine. I haven't had a lot of
time to debug it (im at work, and writing assembler is far from what i
should be doing) but i thought it might be worth letting you guys
know.
The code. It just takes the power of two numbers, returning them as an
exit code. Its not done in the quickest way, but i am just learning at
& t-syntax, so Im playing around. Whatever thoughts you may have are
most welcome.
.section .text
.globl _start
_start:
pushl $3
pushl $2
call power
addl $8, %esp
pushl %eax
pushl $2
pushl $5
call power
addl $8, %esp
popl %ebx
addl %eax, %ebx
movl $1, %eax
int $0x80
.type power, @function
power:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl 8(%ebp), %ebx
movl 12(%ebp), %ecx
movl %ebx, -4(%ebp)
power_loop_start:
cmpl $1, %ecx
je end_power
movl -4(%ebp), %eax
imull %ebx, %eax
movl %eax, -4(%ebp)
decl %ecx
jmp power_loop_start
end_power:
movl -4(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
More information about the yasm-devel
mailing list