News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

STOSD problem.

Started by OceanJeff32, February 21, 2005, 02:21:37 AM

Previous topic - Next topic

OceanJeff32

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

Any good programmer knows, every large and/or small job, is equally large, to the programmer!

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

raymond

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
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

OceanJeff32

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
::)
Any good programmer knows, every large and/or small job, is equally large, to the programmer!