Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does a 64 bit assembly procedure prologue and epilogue look

931 views
Skip to first unread message

Ken Snyder

unread,
Nov 1, 2010, 10:23:14 AM11/1/10
to
Hi,

i guess the subject says it all. What does a
standard prologue and a final epilogue of a
procedure on a 64 bit assembly (Intel/AMD)
look like? Given this:

push ebp
mov ebp,esp
int 3
mov esp,ebp
pop ebp
ret

What would this look like on 64 bit?


thanks in advance

Ken

wolfgang kern

unread,
Nov 1, 2010, 3:58:41 PM11/1/10
to

Ken Snyder asked:

> Hi,

Hello,

Except that assembler language dont really need
HLL-based stackframes and C-styled procedures,
just replace all leading E's with R's:

push rbp ...

__
wolfgang


James Harris

unread,
Nov 1, 2010, 5:16:39 PM11/1/10
to

You only need to

push ebp
mov ebp, esp

as a prologue if you want to set up a stack frame. Similar with your
epilogue. As the code you presented doesn't use a stack frame it could
be written

int 3
ret

Really. That's all you need. The same would work in 32-bit or 64-bit
mode.

James

Rod Pemberton

unread,
Nov 1, 2010, 6:22:19 PM11/1/10
to
"Ken Snyder" <mp5...@hotmail.com> wrote in message
news:iamigj$j8h$02$2...@news.t-online.com...

Your fortunate. I was just about to delete 64-bit Linux for lack of use.

While I can show you what GCC generates, it's possible, that Windows
compilers will generate something different.

Well, first, we have to convert your code to C. C, and other HLL's, use
stackframes. Assembly doesn't need them, although you can use them for
convenience or to interface with C, etc.


Your routine is basically the following function in GCC C using inline
assembly for the INT 3 instruction:

void int3(void)
{
__asm__ (
"int3\n"
);
}

Other C compilers will need different code for the inline assembly.


For 32-bit GCC v3.4.1 and v4.1.0 for DOS (DJGPP), GCC -S generates this for
the C function:

.globl _int3
_int3:
pushl %ebp
movl %esp, %ebp
/APP
int3
/NO_APP
popl %ebp
ret

In the syntax you posted with, and without labels and assembler directives,
that's:

push ebp
mov ebp,esp
int3
pop ebp
ret

The 32-bit code just has the pop for the epilogue. It must be an
optimization for the "void func(void)", i.e., no parameters, no stackframe
on the stack, therefore no need to reset esp.


For 64-bit GCC 4.2.3 for Linux, GCC -S generates this for the C function:

.globl int3
.type int3, @function
int3:
.LFB2:
pushq %rbp
.LCFI0:
movq %rsp, %rbp
.LCFI1:
#APP
int3
#NO_APP
leave
ret
.LFE2:
.size int3, .-int3

In the syntax you posted with, and without labels and assembler directives,
that's:

push rbp
mov rbp,rsp
int3
leave
ret

The 64-bit generates the x86 LEAVE instruction which does the two
instruction esp/ebp portion of the epilogue.

Neither, of course, allocate any arguments, or you'd see a bunch of other
arithmetic manipulations on ESP/RSP.

Depending on what assembler you're using, you may need to qualify the sizes
of the operands. You'll also need to specify the code size, etc.

Those are in GAS (GNU assembler) syntax. It's clear that the GAS syntax has
changed from 32-bit to 64-bit. I don't know that the .type and .size
assembler directives mean. GAS has size qualifier, e.g., 'l' or 'q' etc.,
on the instructions, reverses the operand order, has other differing syntax,
like % on registers.

HTH,


Rod Pemberton

James Van Buskirk

unread,
Nov 1, 2010, 8:12:09 PM11/1/10
to
"Ken Snyder" <mp5...@hotmail.com> wrote in message
news:iamigj$j8h$02$2...@news.t-online.com...

> i guess the subject says it all. What does a


> standard prologue and a final epilogue of a
> procedure on a 64 bit assembly (Intel/AMD)
> look like?

I think you might enjoy:

http://www.agner.org/optimize/calling_conventions.pdf

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Ken Snyder

unread,
Nov 1, 2010, 9:56:09 PM11/1/10
to
Thanks for all answers!

Ken

0 new messages