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

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

array: resw 4096

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.