Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

303

assembler problem

This topic is 6413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''ve been studying some assembler this week just for fun(!)... i think i know the basic stuff, so i tried to do something more advanced today... i got mode 13h working at first time i tried and i can even plot some pixels to the screen (wow! ), but i didn''t get backbuffer (aka virtual screen) working. this routine should clear backbuffer with color 0: mov ax, offset BACKBUFFER ;take offset of backbuffer mov es, ax ;move offset to es:di xor di, di ;dunno if this is needed mov ax, 0 ;source (fill color) mov cx, 32000 ;rep parameter... loop 32000 times rep stosw ;copy ax to es:di and increase di every time i''ve defined BACKBUFFER like this: BACKBUFFER db 320*200 dup (?) what''s wrong with it? when i run it, my system crashes and i have to reboot.

Share this post


Link to post
Share on other sites
Advertisement
Ok I''m a little rusty but here it goes.

xor di,di is a quick way of clearing a register to 0, so you could use this xor ax,ax in place of mov ax, 0.

Your problem, I think, is with the rep stosw, I believe that is meant as a string copy NOT a fill operation, so it''s trying to copy from ??:ax -> es:di and crashing probably from accessing memory illegally.

I don''t recommend coding an entire program in asm, as little things like this crop up all over the place. Coding in C and using asm ( where necessary ) is a good combo.

Good luck.

Share this post


Link to post
Share on other sites
stosw means "es:di=ax" so it''s the right operation for this job. i think movsw is the copy operation you mentioned (but it copies from ds:si, ??:ax is impossible). thanks anyway...

Share this post


Link to post
Share on other sites
I think I can solve your problems.

First of all, ES should be the segment of the backbuffer, not the offset. DI should be the offset.

Also, after putting specific values into ES and DI (or into DS and SI for that matter), you must call the CLD command before using the STOSW command (or related commands). I don''t know why, but it won''t work without it.

Use this and it (should) work:

mov ax, segment BACKBUFFER ;take segment of backbuffer
mov es, ax ;move segment to es
mov di, offset BACKBUFFER ;es:di now contains correct values
cld ;initialise es:di pointer
mov ax, 0 ;source (fill color)
mov cx, 32000 ;rep parameter... loop 32000 times
rep stosw ;copy ax to es:di and increase di every time

Share this post


Link to post
Share on other sites

yep, that worked... thanks.
i am using tiny memory model, so i don''t have to play with segments.. but i moved offset of backbuffer to di instead of es and then it did work ofcourse.

Share this post


Link to post
Share on other sites
Well, I finally found out what CLD does... it sets the direction bit in the flags register to 0 (forwards). If some other part of your program has used STD, then the direction bit will be 1 (backwards). This occurs in some standard functions. So take note of this... if the direction is backwards, then the relavent pointer(s) will actually be decremented when you use a STOSx / MOVSx / LODSx command.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!