Re: Buffers in Assembly (NASM)



On Fri, 18 Jul 2008 19:34:08 -0700 (PDT), "bwaichu@xxxxxxxxx"
<spamtrap@xxxxxxxxxx> wrote:

I'm trying to better understand data structures in assembly. I know I
can create a zero filled buffer in the bss section in NASM with this:

The bss section is by definition not initialized by the program, so
you have to clear it yourself.

buffer: times 64 db 0
This should get an error in the bss section.


And I know I can create a buffer on the stack like this:

sub esp, 64
mov ebx, esp ;save the start point of the buffer

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
--
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

  • Re: Buffers in Assembly (NASM)
    ... can create a zero filled buffer in the bss section in NASM with this: ... it doesn't know what ".bss" means. ... In an uninitialized section, there's "nothing there", so it would be "conceptually impossible" for Nasm to zero it. ... mov al, 'N' ...
    (comp.lang.asm.x86)
  • Re: Buffers in Assembly (NASM)
    ... it doesn't know what ".bss" means. ... In other formats, this will ... Nasm to zero it. ... I'm basically just creating a buffer to write strings for functions ...
    (comp.lang.asm.x86)
  • Re: static char overflow
    ... > you can see your buffer is located at bss section and there isnt another ... There is no static heap section afterwards, ... entire dynamic heap is initialized after the .bss section, ... I heard that it can be exploited in old linux if it is ...
    (Vuln-Dev)
  • Re: referring to segments other than DS - how?
    ... only have 16-bit registers, and I've got a buffer in BSS, how do I write ... needs the address of the buffer to be in DS:DX, so I have to move the BSS ... EncFileHandle; file handle to bx ... I'm trying not to use 32-bit registers. ...
    (alt.lang.asm)
  • Re: Static allocation failure?
    ... adjust the heap size. ... the BSS with memory from the heap, if I set my heap size way larger ... The compiler generates a series of fragments which the linker then ... How big does the stack need to be? ...
    (comp.arch.embedded)