The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: OceanJeff32 on February 21, 2005, 02:21:37 AM

Title: STOSD problem.
Post by: OceanJeff32 on February 21, 2005, 02:21:37 AM
Yes, another problem.  I have a program that uses REP STOSD.  I couldn't get it to run, and I know from debugging that it stops at REP STOSD or even STOSD, it crashes the program (not windows).

I might be setting up the es:(e)di pointer wrong.

Here's what I did...

mov esi, bitmap1
mov edi, 0            ; point to beginning.
cld
mov ecx, amount
mov eax, colorpixel

rep stosd

Is this wrong?  I can't figure it out, I was working fine with rep stosd and this stuff in DEBUG, but now with MASM32 it will assemble, but not run.

Thanks,

Jeff C
:eek

Title: Re: STOSD problem.
Post by: donkey on February 21, 2005, 03:05:19 AM
STOSD will mov the DWORD in EAX to the address pointed to by the EDI register and increment or decrement it based on the state of the direction flag, the REP opcode will repeat this ECX times. In the code you posted you have set EDI to 0, obviously an address of 0 will GPF, it is invalid.
Title: Re: STOSD problem.
Post by: raymond on February 21, 2005, 04:09:37 AM
Jeff

If you are trying to duplicate code you may have used previously in 16-bit assembly, you will create yourself some problems. In 32-bit programming, you don't want to fool around with the segment registers, yet (or ever).

Use donkey's suggestion and load EDI with the actual address where you want to use the stosd.

Raymond
Title: Re: STOSD problem.
Post by: donkey on February 21, 2005, 04:25:44 AM
I guess I should note that ES:EDI in this case has nothing at all to do with ESI as you seem to have assumed. ESI actually is used as a pointer to data in the DS segment (source pointer) and EDI to data in the ES segment (destination pointer) when using segmented (non-flat) memory models. ES is an alternative data segment register, there are 4 in all DS, ES, FS and GS, and though they are used in the manuals, in the flat model they are all pointing to the same base address so you ignore them. The only thing you have to concern yourself with is the 32 bit address in EDI.
Title: Re: STOSD problem.
Post by: OceanJeff32 on February 21, 2005, 05:24:08 AM
Thanks Donkey (hee-haw!)

I got it! And I posted a fixed and optimized version in the Laboratory.

That was what I needed to know.

Later,

Jeff C
::)