Hi
I'm dissecting a Fortran function (32-bit) to see how things
get passed around and returned. Unlike C, Fortran calls by
reference so pointers are automatically passed in function
args, and the function's return value must be assigned to the
function name before returning.
Here's the function:
integer function incr(k)
incr = k + 1
return
end
And a main program if anyone is adventurous enough to run it:
integer k
k = 0
k = incr(k)
print *, k
end
And here's the output listing incr.s from gfortran -S incr.f,
with a few of my comments:
.file "incr.f"
.text
.globl incr_
.type incr_, @function
incr_:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl 8(%ebp), %eax ;eax gets addr of 1st arg
movl (%eax), %eax ;gets contents of addr
addl $1, %eax ;increment eax
movl %eax, -4(%ebp) ;save return value
movl -4(%ebp), %eax ; ???
leave
ret
.size incr_, .-incr_
.ident "GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
.section .note.GNU-stack,"",@progbits
My question is, What is going on in the last two movl ops?
It looks like the 2nd movl is just doing the reverse of the
1st movl, like a=b followed by b=a.
Michael