Jump to content
  • Advertisement

Archived

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

Red Drake

Help with assembler

This topic is 5286 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

Well i need help I am begining to learn assembler (buth i don't think this is for the beginers forum) and I am focusing on the SIMD. so this function is writen in NASM segment .text global _Math_AMD_3DNOW_Vector3_ADD _Math_AMD_3DNOW_Vector3_ADD: femms lea eax, [ebp+8] lea ebx, [ebp] movd mm0,[eax] movd mm1,[ebx] pfadd mm0,mm1 movq mm1,[eax+8] movq mm2,[ebx+8] pfadd mm1,mm2 movq [eax] ,mm0 movd [eax+8] ,mm1 femms ret and its linked in the c troug .obj file format In c I call the "_Math_AMD_3DNOW_Vector3_ADD" and give it an pointer of 2 x 3D vector (X,Y,Z) The result is (at least shoud be) returnd in to first parameter (trough pointer). The code compiles ok , i dont get any errors but i don't get any results back !! I look at the vectors that hawe pased this function and they remain the same. Do you know why??? P.S. Sory about gramatical errors [edited by - Red Drake on May 31, 2004 1:49:12 PM] [edited by - Red Drake on May 31, 2004 2:06:46 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Red Drake
Is there some one that can code SIMD - 3DNOW , and can help me ???

It''s not even been 2 hours since your original post, and it seems to be a pretty specific topic. A response will come if someone knows the answer.

Share this post


Link to post
Share on other sites
Ok, ok
It''s yust that I hawe been trying to make this work for like ?? all day and its about 22:00 hear (I started at 12:00) so I am quite crazy right now (try this and try that,and again , and again, go to google search ...).
And I get a fealing that if nobody responds to your question in 2 h or so you probably wont even get an anwser
+ I hawe 56k dialup modem so my bill is pumping while I am waiting
I am so angry at my computer - compiler that I coud yust smash it - hopfuly it wont come to that - so if anybody knows an anwser to the question you bether write in or my computer may suffer som critical hits (on the monitor, keyboard ....)
I thing that game development is one of the most stresfull things to do :

Share this post


Link to post
Share on other sites
In vecadd.h write:


#ifndef VEC3DNOW
#define VEC3DNOW

struct Vec3D
{
float x;
float y;
float z;
};

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

#endif



In vecadd.asm write:


segment .text

global _Math_AMD_3DNOW_Vector3_ADD

;
; void _Math_AMD_3DNOW_Vector3_ADD(Vec3D* a, Vec3D* b);
;
_Math_AMD_3DNOW_Vector3_ADD:

; create stack frame
push ebp
mov ebp, esp

; load pointers, eax = a, edx = b
mov eax, [ebp + 8]
mov edx, [ebp + 12]

; add x and y
movq mm0, [eax]
pfadd mm0, [edx]
movq [eax], mm0

; add z
movd mm0, [eax + 8]
pfadd mm0, [edx + 8]
movd [eax + 8], mm0

; make floating point save
femms

; destroy stack frame
pop ebp

; return
ret




[edited by - nmi on May 31, 2004 4:11:34 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Red Drake
I thing that game development is one of the most stresfull things to do :

It wouldn''t be special if it weren''t. And you wouldn''t want it any other way anyway, right?

Share this post


Link to post
Share on other sites
A question to nmi:
isn't pfadd used to add two mmx registers ??
And why do you create a stack ? (I mean I dont use it in this function).
I am going to test your code now :|
Thanks

and to Woodsman :
Whel any more stress to me today and I woud hawe an mayor brakedown

[edited by - Red Drake on May 31, 2004 4:20:18 PM]

Share this post


Link to post
Share on other sites
As the manual says:

PFADD mmreg1, mmreg2/mem64 0Fh 0Fh / 9Eh Packed, floating-point addition

So you could specify another register or a memory location.

The stack frame is created to access the pointers, a and b. If you like you may change the code to the following:


_Math_AMD_3DNOW_Vector3_ADD:

; get params
pop ecx
pop eax
pop edx

; add x and y
movq mm0, [eax]
pfadd mm0, [edx]
movq [eax], mm0

; add z
movd mm0, [eax + 8]
pfadd mm0, [edx + 8]
movd [eax + 8], mm0

; make floating point save
femms

; prepare return
push edx
push eax
push ecx

; return
ret


[edited by - nmi on May 31, 2004 4:31:40 PM]

Share this post


Link to post
Share on other sites
Your first code does not work !!

the debug from Visul c++ :

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

P.S. Do you know does creating a stack takes more thime (significantly) ??

Share this post


Link to post
Share on other sites
I think you are using NASM ? At least NASM assembles the file without any error. Maybe you should try that. Then insert the object file into your Visual C++ source tree.

The thing about stack frames is that every function saves the old base pointer and then loads the base pointer with the value for its own stack frame. The base pointer may be used to access parameters or local variables. When calling other functions from your assembler code, you should use stack frames. Here we don''t need it, but we may use it. Compared to the 3Dnow! addition it comes almost for free (consider caches etc.)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!