Re: Buffers in Assembly (NASM)



On Sat, 19 Jul 2008 11:16:14 -0700 (PDT), "bwaichu@xxxxxxxxx"
<spamtrap@xxxxxxxxxx> wrote:

On Jul 19, 1:18 am, ArarghMail807NOSPAM <spamt...@xxxxxxxxxx> wrote:
But how do I zero out the buffer on the stack? In C, I would just do
something like:

char buffer[64] = {0};

Which does what I show below.

What's the equivalent in assembly using NASM?

This will work for either the stack, or bss: (baring typos)
xor al,al
mov ecx,64
lea edi,buffer ; may need [] ?
rep stosb

OR:
xor eax,eax
mov ecx,16
lea edi,buffer ; may need [] ?
rep stosd

That works well. I just did this:

sub esp, 64
mov dword edi, esp ;store the location of the beginning of the buffer
in edi

xor eax, eax ; make sure al is zero for the call to stosb
mov dword ecx, 64 ; set counter to 64
rep stosb ; repeat stosb 64 times -- this could be done faster with
stosd 16?
That mostly depends on the processor in question.

Does stosb move up the stack by default or do I need to explicitly
specify the direction with cld?

stosb follows the direction bit.

In my programs, I generally clear it during initialization, and clear
it as soon as possible after setting it.
--
ArarghMail807 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.

.



Relevant Pages