The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 07:49:49 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  STOSD problem.
« previous next »
Pages: [1] Print
Author Topic: STOSD problem.  (Read 4803 times)
OceanJeff32
Hobbyist Programmer (Games / Graphics)
Member
*****
Gender: Male
Posts: 173


This is me laying back, relaxing.


STOSD problem.
« 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

Logged

Any good programmer knows, every large and/or small job, is equally large, to the programmer!
donkey
Member
*****
Posts: 3789


ASS-embler


Re: STOSD problem.
« Reply #1 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.
Logged

"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
Member
*****
Gender: Male
Posts: 941


Aging newbie


Re: STOSD problem.
« Reply #2 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
Logged

When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com
donkey
Member
*****
Posts: 3789


ASS-embler


Re: STOSD problem.
« Reply #3 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.
Logged

"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
Hobbyist Programmer (Games / Graphics)
Member
*****
Gender: Male
Posts: 173


This is me laying back, relaxing.


Re: STOSD problem.
« Reply #4 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
Roll Eyes
Logged

Any good programmer knows, every large and/or small job, is equally large, to the programmer!
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!