Subject: adventures in as
To: None <netbsd-help@netbsd.org, port-i386@netbsd.org>
From: None <collver@linuxfreemail.com>
List: port-i386
Date: 02/23/2002 23:09:06
My system is an Intel x86 running NetBSD 1.5.2.
I am poking around with as and gdb, and am confused.

18              leave
(gdb) p $ebp
$1 = (void *) 0xbfbfd7b0
(gdb) p $esp
$2 = (void *) 0xbfbfd7b0
(gdb) s
main () at test.s:19
19              ret
(gdb) p $ebp
$3 = (void *) 0xbfbfd7d4
(gdb) p $esp
$4 = (void *) 0xbfbfd7b4

The confusing part is that the "leave" opcode should move the value from
ebp into esp, then pop the value from the stack into ebp.  So I expected
esp to end up being 0xbfbfd7b0, not 0xbfbfd7b4.  Can anyone give me an
idea why gdb is showing unexpected results for "leave"?

# echo -e '#include <stdio.h>\nmain(){puts("hi there");}' >test.c
# gcc -S test.c
# as --gstabs -o test.o test.s
# ld -m elf_i386 -dc -static \
   /usr/lib/crt0.o /usr/lib/crtbegin.o test.o -lgcc -lc /usr/lib/crtend.o
# gdb ./a.out

Regards,

Ben