Skip to main content
GameDev.net gamedev.net
🔒 Locked

ASM Math Trouble

Started by SimDemon Feb 21, 2003 at 6:15 PM 6 replies 250+ views
Original Post
SimDemon
SimDemon
Hello, there. I was testing to see how much faster my computer did basic addition using ASM and regular C/C++ code. The only compiler error is in the ASM section. I am also using class templating. template class ASM { public: MathASM Add(MathASM val1, MathASM val2) { // I Don''t Know What to Do Here // Tried this: /* __asm { PUSH ax ADD val1,val2 MOV ax,val1 RET } } }; int main() { MathASM math; int n = math.Add(10, 2); cout << "N = " << n << "\n\n"; return 0; } Please help. I am using MS Visual C++ 6.0. Thanks, Matt U. If thispost = 0 Then GoBack() Else Read() End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
jperalta
jperalta
The add operator cannot operate on two variables so do:

mov ax,val1
add ax,val2
mov result,ax

-- Exitus Acta Probat --
NickB
NickB
The only thing I''d point out is that this test probably won''t have any meaningful result - when you get it to work you''ll probably find that using C++ or ASM will be just as fast, as this is a very simple bit of maths that any compiler will probably compile to more or less what you''ve written. The advantages of asm only really start to show through when you reach a situation the compiler can''t resolve as well (like using MMX to do packed data operations)
SimDemon
SimDemon
Yes, I have figured that out. The time for the ASM and C functions are equal. Could you please give an example that I could use to tell a difference in ASM and C?

Thanks,
Matt U.

If thispost = 0 Then
GoBack()

Else
Read()
End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
walkingcarcass
walkingcarcass
If you want to accuratly test the time of a piece of code, you will need to look at the RDTSC or RDPMC instructions. Bear in mind these instructions take a relativly large number of cycles to execute, and may experience out-of-order execution problems.

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back
spraff.net: don't laugh, I'm still just starting...
Scrime
Scrime
You could take a look at the ASM generated by the C code that you write and then compare it to you hand-coded ASM code.

- What we need is duty now for the future!
We are the music makers and we are the dreamers of the dreams. - WonkaAsking Smart Questions | BookPool

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.