Help with assembler

Started by
17 comments, last by Red Drake 19 years, 10 months ago
I am using NSAM and GCC (dev-cpp)
The thing you saw was an debug of my app after it reprted an illegal operation ! It hapend to me a couple of times before !!
As I said : I am so angry at my computer - compiler that I coud yust smash it.
P.S.
I newer tryed code like yours buth it hapend in similar situations

[edited by - Red Drake on May 31, 2004 4:59:53 PM]
Red Drake
Advertisement
I recommend using DJGPP. However other compilers may do it as well.
It''s not the complier!
The app compiles corectly and I run it (on windows) and then get an mesage
"Ilegal operation in .... bla bla bla"
And after i press the debug buton I get the code

00401340 push ebp
00401341 mov ebp,esp
00401343 mov eax,dword ptr [ebp+8]
00401346 mov edx,dword ptr [ebp+0Ch]
-> 00401349 movq mm0,mmword ptr [eax] // Error
0040134C pfadd mm0,mmword ptr [edx]
00401350 movq mmword ptr [eax],mm0
00401353 movd mm0,dword ptr [eax+8]
00401357 pfadd mm0,mmword ptr [edx+8]
0040135C movd dword ptr [eax+8],mm0
00401360 femms

in my Visual Studio debuger
So any known reasons for that
P.S.
I hawe tried the second code buth it does not work eather
Red Drake
Can you post the code where you call the function ?

Try this example:

#include "vecadd.h"#include <iostream>using namespace std;int main(){  Vec3D a = { 1.0, 2.0, 3.0 };  Vec3D b = { 4.0, 6.0, 8.0 };  Math_AMD_3DNOW_Vector3_ADD(&a, &b);  cout << "result: ("   cout << a.x << ", " << a.y << ", " << a.z;  cout << ")";  cout << endl;  return 0;}



[edited by - nmi on May 31, 2004 5:21:17 PM]
Hear it is in c
#include <stdio.h>#include <stdlib.h>struct Vec3{    float X,Y,Z;};    extern "C" {void Math_AMD_3DNOW_Vector3_ADD(Vec3 V1, Vec3 V2);} int main (void){    Vec3 V,U;    V.X = 3.0f;    V.Y = 0.5f;    V.Z = 5.3f;    U.X = 2.30f;    U.Y = 3.0f;    U.Z = 0.2f;    Math_AMD_3DNOW_Vector3_ADD(V,V);    printf ("\n %f %f %f ",V.X , V.Y ,V.Z );        return 0; }   


and in asm

0x40128c :	push   ebp0x40128d :	mov    ebp,esp0x40128f :	sub    esp,0x380x401292 :	and    esp,0xfffffff00x401295 :	mov    eax,0x00x40129a :	mov    DWORD PTR [ebp-44],eax0x40129d :	mov    eax,DWORD PTR [ebp-44]0x4012a0 :	call   0x4036f0 0x4012a5 :	call   0x4020d0 0x4012aa :	mov    DWORD PTR [ebp-24],0x404000000x4012b1 :	mov    DWORD PTR [ebp-20],0x3f0000000x4012b8 :	mov    DWORD PTR [ebp-16],0x40a9999a0x4012bf :	mov    DWORD PTR [ebp-40],0x401333330x4012c6 :	mov    DWORD PTR [ebp-36],0x404000000x4012cd :	mov    DWORD PTR [ebp-32],0x3e4ccccd0x4012d4 :	sub    esp,0x200x4012d7 :	mov    edx,esp0x4012d9 :	mov    eax,DWORD PTR [ebp-24]0x4012dc :	mov    DWORD PTR [edx+12],eax0x4012df :	mov    eax,DWORD PTR [ebp-20]0x4012e2 :	mov    DWORD PTR [edx+16],eax0x4012e5 :	mov    eax,DWORD PTR [ebp-16]0x4012e8 :	mov    DWORD PTR [edx+20],eax0x4012eb :	mov    eax,DWORD PTR [ebp-24]0x4012ee :	mov    DWORD PTR [edx],eax0x4012f0 :	mov    eax,DWORD PTR [ebp-20]0x4012f3 :	mov    DWORD PTR [edx+4],eax0x4012f6 :	mov    eax,DWORD PTR [ebp-16]0x4012f9 :	mov    DWORD PTR [edx+8],eax0x4012fc :	call   0x401340 0x401301 :	add    esp,0x200x401304 :	sub    esp,0x40x401307 :	fld    DWORD PTR [ebp-16]0x40130a :	lea    esp,[esp*1-8]0x40130e :	fstp   QWORD PTR [esp*1]0x401311 :	fld    DWORD PTR [ebp-20]0x401314 :	lea    esp,[esp*1-8]0x401318 :	fstp   QWORD PTR [esp*1]0x40131b :	fld    DWORD PTR [ebp-24]0x40131e :	lea    esp,[esp*1-8]0x401322 :	fstp   QWORD PTR [esp*1]0x401325 :	push   0x4012800x40132a :	call   0x405140 0x40132f :	add    esp,0x200x401332 :	mov    eax,0x00x401337 :	leave  0x401338 :	ret       




[edited by - Red Drake on May 31, 2004 5:23:45 PM]
Red Drake
The problem is here:

quote:
extern "C" {void Math_AMD_3DNOW_Vector3_ADD(Vec3 V1, Vec3 V2);}


You pass the parameters by value, so you just put a copy onto the stack when calling the function. Whether the function changes the values or not, the copy won't affect the original.

Please use the other variant:

extern "C" void Math_AMD_3DNOW_Vector3_ADD(Vec3* a, Vec3* b);


By passing pointers to the data, the function is able to modify its contents. Now you should see how the values are changing.

[edited by - nmi on May 31, 2004 5:32:51 PM]
You are right
I totaly fuc*d my self.
I did not think for a single moment that this is it
Thank''s man !
Now instead of "I am so angry at my computer - compiler that I coud yust smash it" it''s "I am so angry at my self that I coud start hiting my head of the wall.)
And the funiest part is that when I started to learn SIMD this morning up uuntil now I was doing hundreds of stuff that didn''t even mather !!!!!!!!!!!!!!!
As I said "I am goin to start hiting my head of the wall"
And sory for the time that I hawe taken you
Red Drake
quote:
Your first code does not work !!


It does work for me, so either your processor is too old, or probably your data is not aligned properly


My Site

[edited by - Quasar3D on May 31, 2004 5:36:58 PM]
quote:Original post by Red Drake
You are right
I totaly fuc*d my self.
I did not think for a single moment that this is it
Thank''s man !
Now instead of "I am so angry at my computer - compiler that I coud yust smash it" it''s "I am so angry at my self that I coud start hiting my head of the wall.)
And the funiest part is that when I started to learn SIMD this morning up uuntil now I was doing hundreds of stuff that didn''t even mather !!!!!!!!!!!!!!!
As I said "I am goin to start hiting my head of the wall"
And sory for the time that I hawe taken you


No problem. Maybe it''s already somewhat late... ;-)

However learning SIMD is just as easy as taking the manual. Teaching SIMD to your compiler is somewhat harder...

This topic is closed to new replies.

Advertisement