i want to reserve 4096 bytes in the memory and initialize all with zeros
how should i do that?

mov byte[array:di],0
inc di
cmp di,4096
jne initialize

array: resw 4096

6 Years
Discussion Span
Last Post by NotNull

don't use a loop. See this link

mov ecx,4096
mov edi,offset ???
xor eax,eax ; set eax = 0
rep stosb

You can inprove the performance of that a tiny bit by using stosd and storing in ecx the count of dwords instead of bytes

Edited by Ancient Dragon: n/a


I noticed you're using 16-bit assembler, similar in syntax to 32-bit.
For the string initialization instruction, STOS it takes an initializer
in the accumulator and a pointer to the string to initialize in ES : DI.
For a 4096 byte array do:

mov cx, 4096 ; initialize 4096 bytes
cld ; Direction UP - to higher addresses
mov es, seg arr ; make ES:DI refer to string
mov di, offset arr 
rep stosb ; initialize string

STOSB with DF==0 is equivalent to:

mov [es:di], al
inc di

Assuming 4096 fits into DWORDS (which it does), stosd is not available in real-mode
or V8086 mode assuming the poster was intending 16-bit code, (indicated by the use
of DI instead of EDI), 4096 bytes equals 2048 WORDS and the STOSW instruction may
be used to increase performance, there will be a performance increase further
if the array of WORDS lies at an address evenly divisible by two.

Edited by NotNull: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.