From: Frank Kotler <fbkotler@comcast.net>
To: Niel A <amerei@gmail.com>
Cc: "linux-assembly@vger.kernel.org" <linux-assembly@vger.kernel.org>
Subject: Re: hello again :D
Date: Sun, 08 Jan 2006 11:19:56 -0500 [thread overview]
Message-ID: <43C13BAC.6020504@comcast.net> (raw)
In-Reply-To: <20060108132150.0c5ea4b4.amerei@gmail.com>
Niel A wrote:
> wow! thanks! i think i understand it now a little! actually, i re-read your email a couple of times, then resorted to whipping up something in c before finally seeing some light.
>
> -----------------------------------------
> sub esp, move_end - move_me
> and esp, -8
> -----------------------------------------
>
> you allocated space on the stack
By subtracting something from esp.
> but fall back on the next lowest 8 byte boundary. but that would mean that the stack is now a little short on space for the size of the function that you wanna copy on it right?
No, that gives us a little extra!
(low 8 bits)
Suppose the stack starts at 0xBFFFF780 ...10000000
subtract 9 bytes for our code 0xBFFFF777 ...01110111
(and -8) ...11111000
------------
and esp, -8 (0xFFFFFFF8) 0xBFFFF770 ...01110000
So we've got a full 16 bytes "reserved".
> is this ok? i'm so sorry. *gomen*. still a bit blurry. perhaps i'm just thinking about it so much.
I've been known to confuse myself by thinking too much about the fact
that the stack "grows down". I can get to thinking that my whole memory
is "upside down". It isn't, of course, the stack uses pefectly ordinary
memory. The stack *pointer*, esp, moves "downward" (smaller value) when
we add something to the stack with a push or call. This is called the
"top" of stack... Previous values on the stack remain at the same
address (of course), but with respect to esp, they're at a bigger
*negative* offset as we add more to the stack.
How do we diagram/envision memory? With high numbers at the top, I
suppose, and zero at the bottom. This way, the stack "grows down", but
the "top of stack" is at the bottom. Another natural way would be 0, 1,
2, 3 with zero at the top. This is the way our source code reads...
instructions at the top go into lower memory, and as we read "down"
instructions are going into higher addresses. In this orientation, "top
of stack" is at the top, but the stack grows "upward"... as it works
into lower addresses. No wonder we're confused!
I'm not sure that helps... or otherwise. Observing C output may help.
Stepping through your code in a debugger might be better. I like ald
(available at SourceForge) better than gdb. Actually, I use an older
version of ald - reminds me more of DEBUG (how's *that* for faint
praise? :) For debugging, use the "-g" switch for Nasm, and *don't* use
the "-s" switch to ld. It helps a *lot* if you start off with a "nop"
(right after "_start:") - gives gdb someplace to set a breakpoint, so
you can step through your code from the beginning. Seems to matter less
with ald.
Hang in there!
Best,
Frank
next prev parent reply other threads:[~2006-01-08 16:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060107110622.65f5623a.amerei@gmail.com>
2006-01-07 3:15 ` hello again :D Ricardo Nabinger Sanchez
2006-01-07 3:17 ` Ricardo Nabinger Sanchez
2006-01-07 3:32 ` Frank Kotler
2006-01-07 3:40 ` joy merwin monteiro
2006-01-07 5:00 ` Frank Kotler
2006-01-07 5:26 ` joy merwin monteiro
2006-01-08 5:17 ` Niel A
2006-01-08 1:41 ` Frank Kotler
[not found] ` <47c1bd210601080024rf8ae88ey4d136c08af3943fd@mail.gmail.com>
2006-01-08 14:40 ` Frank Kotler
[not found] ` <20060108132150.0c5ea4b4.amerei@gmail.com>
2006-01-08 16:19 ` Frank Kotler [this message]
2006-01-12 9:52 ` Hendrik Visage
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43C13BAC.6020504@comcast.net \
--to=fbkotler@comcast.net \
--cc=amerei@gmail.com \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).