Advertisement

inline ASM and arrays.

Started by January 31, 2000 04:04 PM
7 comments, last by fredo 24 years, 10 months ago
I think I may have found a bug in the Visual C 6.0 compiler. Can anyone identify what's happening here cause I'm out of ideas. It seems that even though EBX is pointing to the location of TempArray, nothing seems to be updating. void func(DWORD *dwSurface) { DWORD TempArray[8]={0,0,0,0,0,0,0,0}; __asm { lea ebx,TempArray mov esi,dwSurface // this does not update the contents of AnArray movs [dword ptr ebx],[dword ptr esi] movs [dword ptr ebx+4],[dword ptr esi+4] movs [dword ptr ebx+8],[dword ptr esi+8] movs [dword ptr ebx+12],[dword ptr esi+12] movs [dword ptr ebx+16],[dword ptr esi+16] movs [dword ptr ebx+20],[dword ptr esi+20] movs [dword ptr ebx+24],[dword ptr esi+24] movs [dword ptr ebx+28],[dword ptr esi+28] // neither does this mov ecx,8 rep movs [dword ptr ebx],[dword ptr esi] } } So if anyone has seen this problem and knows what's going on, then please let me in on the big conspiracy. Thanks ~-------------------------------------------------------~ Fred Di Sano System Programmer - Artech Studios (Ottawa.CA) ~-------------------------------------------------------~ Edited by - fredo on 1/31/00 4:19:08 PM Edited by - fredo on 1/31/00 4:20:14 PM
~-------------------------------------------------------~ Fred Di Sano System Programmer - Artech Studios (Ottawa.CA)~-------------------------------------------------------~
I''m a little rusty with my IBM assembly (I mostly use assembly on the Mac) but could it be that your''re doing a "move single byte" with a "double byte ptr"? Sorry, I normaly check my notes with assembly but I don''t have them with me right now. (Plus, I havn''t used assembly with an array before on an IBM)

If I''m blowing hot air here just tell me.

E:cb woof!
E:cb woof!
Advertisement
Nope. I''m actually copying a dword. The expression:

movs [dword ptr ebx],[dword ptr esi]

explicitly says DWORD to DWORD. The problem is that NOTHING is getting copied over.

~-------------------------------------------------------~
Fred Di Sano
System Programmer - Artech Studios (Ottawa.CA)
~-------------------------------------------------------~
~-------------------------------------------------------~ Fred Di Sano System Programmer - Artech Studios (Ottawa.CA)~-------------------------------------------------------~
Sorry. I thought that "movs" was "move single".

E:cb woof!
E:cb woof!
Sorry if this seems a thick answer, but shouldn''t you move a pointer to esi?
I''m not too sure of my grounding here - so don''t hold me to it.

take it easy,

-Mezz
My random thoughts on this:

* Maybe try MOVSD (move string DWORD)? SI and DI get incremented by 4 when this is used automatically.

* Doesn''t using the MOVS instruction increment SI automatically so you shouldnt have to do SI+4 then SI+8, etc. Or am I off?

Hope this helps some. --Nolan (rasputin@value.net)
Advertisement


Hehe...ok, I''m going to field all 3 replies in one shot.

Dog135: Sorry. I thought that "movs" was "move single".

No problem, I believe 6800x0 assembly actually does that.

Mezz: Sorry if this seems a thick answer, but shouldn''t you move a pointer to esi? I''m not too sure of my grounding here - so don''t hold me to it.

I''m not exactly sure what you mean. I''m trying to move one DWORD of data from ESI to EBX.


nolan: My random thoughts on this:

* Maybe try MOVSD (move string DWORD)? SI and DI get incremented by 4 when this is used automatically.

* Doesn''t using the MOVS instruction increment SI automatically so you shouldnt have to do SI+4 then SI+8, etc. Or am I off?


I know about MOVSD instruction and how it works but in this specific case, I wanted to move data from ESI to EBX and so I explicitly use the MOVS instruction to this which in this case (as I just discoverd) ALWAYS increments ESI and EDI. So even though I''m calling it like this:

movs [dword ptr ebx],[dword ptr edi]

Which should move a DWORD from ESI to EBX, it doesn''t move anything to EBX but still increments ESI and EDI by 4.

That''s what I was wondering about.

~-------------------------------------------------------~
Fred Di Sano
System Programmer - Artech Studios (Ottawa.CA)
~-------------------------------------------------------~
~-------------------------------------------------------~ Fred Di Sano System Programmer - Artech Studios (Ottawa.CA)~-------------------------------------------------------~
I think the problem is related to using movs for a DWORD move with a destination other than edi. Regardless, you are probably better off using the DWORD version of the string move. The following code works as expected when I compiled it under Visual C++ 6.0:

lea edi,TempArray ;Be sure to use EDI and ESI for the
mov esi,dwSurface ;string moves
mov ecx,8
rep movsd

Hope this is helpful.
Well, what it all comes down to is that:

movs [dword ptr ebx],[dword ptr esi]

for whatever reason DOESN''T copy a DWORD from ESI to EBX and so I re-wrote the algorithm to do straight DWORD moves.

Thanks to all who gave their input.

~-------------------------------------------------------~
Fred Di Sano
System Programmer - Artech Studios (Ottawa.CA)
~-------------------------------------------------------~
~-------------------------------------------------------~ Fred Di Sano System Programmer - Artech Studios (Ottawa.CA)~-------------------------------------------------------~

This topic is closed to new replies.

Advertisement