|
-
Aug 20th, 2003, 03:01 AM
#1
Thread Starter
Addicted Member
C++ and assembly [Resolved]
well, i know one thing:
there is a keyword __asm in c++ 
sure thats not news, but guess i want to know more about that.
i have decieded to send this thread in assembly forum because i assumed that people who program assembly know c++, but not nessarily vice versa.
the point i want to get from __asm keyword is performance,
as i am trying to make an AI chess program i thought that inserting direct assembly code in the c++ program will boost performance.
PS: i am NOT an assembly programmer, but trying to figure out if its worth the trouble to start learning it.
is that a reasonable idea ???
would it be really better to use assembly ??
another thing, is there limitation on __asm ??
i mean are all assembly statements and stuff available ???
also, can i use c++ compiler as an assembler, intead of getting a seperate assembler ???
for example:
Code:
void main(){
__asm{
/* some assembly code */
}
}
does that have disadvantages ??!
also, as i have no idea about assembly language, i'd find it usefull to know few other stuff:
* does assembly provide the idea of "function" or "sub" ??
* does assembly provide the idea of a class ??
* can i make a dll file ??
* back to __asm keyword, does c++ change 1 statement into 1 assembly intruction. i mean would i find a statement which is lets say 5 assembly instruction, that i can do manually in assembly in one or two assembly instruction ?? (can u provide an example ?? )
thx in advance for trying to answer one or all of my questions.
Last edited by ZaidGS; Aug 31st, 2003 at 06:00 AM.
-
Aug 20th, 2003, 07:51 PM
#2
Hyperactive Member
ZaidGS,
From what I know about asm, whether you would be able to get performance gains by using asm,depends on what you are doing and that you know what your doing with asm.
As for the __asm keyword in c++.
As your probably well aware, c++ code gets turned into asm. So by cutting out unnessasry things you should be able to speed things up.
For an example? I couldnt give an example code of the differences off hand.
* does assembly provide the idea of "function" or "sub" ??
-Yes procedures.
* does assembly provide the idea of a class ??
-Yea sorta, a guy that goes by the name NAN has made classes possible by using asm macro's (in masm).
* can i make a dll file ??
-Yes, both native and COM.
Again, if you know what your doing you can get a performance boost from using asm. But unless its a real intensive program, you may on see a minor performance boost expecially on todays systems.
However, you should learn asm if you have the time. Youll have a better undestanding of what the c++ compilers are doing. And It does have other benifits besides performace, like smaller exec. Also you dont have to deal with c++ casting of datatypes. Which I hate with a passion. 
If you start learning I would suggest learning masm. Its from big Micro$oft and easy to learn. Also there is a free, kick butt IDE called RADASM that makes GUI a snap. Its at http://www.visualassembler.com/radasm/
If you more used to the Visual C++ IDE, there is one thats very similiar. It lacks a integrated resource editor but is free. Assembly Studio available at http://www.negatory.com/asmstudio/
Anyway hope I answer some of your questions. If you want more and better answers about asm you could try to post them at
http://board.win32asmcommunity.net/
Really helpful people that post at this board and you dont get attitude as much as around the c++ community.
Wow that was probably too much info.
-
Aug 21st, 2003, 02:14 AM
#3
Thread Starter
Addicted Member
a little bit of explanation
first of all, thanks packetVB 
ok, i though it might be usefull to give some further explanation of my situation.
as i said, i am making a chess AI program, so performance is key.
i'll give you some statistics on that:
refering to first move on chessboard, and depth 8:
* VB6 in debug mode needs more than 5 minuits
* VB6 optimized for speed needs 135 sec
* VB.NET optimized needs 135 sec
* VC++6 in debug mode needs 85 sec
* VC++6 optimized needs 18 sec
* VC++.NET (using managed classes, and managed arrays) in debug mode needs 140 sec
* VC++.NET (using managed classes, and managed arrays) optimized needs 125 sec
i have programmed this chess engine first on VB6 , and converted a final version of that into VC++, so as u see the ratio between optimized versions of VC++ : VB is nearly 1 : 8 , which allows to to increase the depth by two, with a slight increase in time. ie. from default depth 5 in VB to default depth 7 in VC++.
i thought maybe for especially loop using assembly can make a time save of at least a ratio 3 : 4, maybe doing that in 13 sec ...
on your estimation could that benefit be possible, or is VC++ so fast that assembly would not make that big difference ???
also, as i was browsing the net, i found this site:
http://www.eventhelix.com/RealtimeMa...ranslation.htm
although i did not understand anything, i sensed it should be usefull .........
well, well, if smone would check it, and tell me if its worth the trouble understanding what they are saying.
there they explain how to translate C++ code into assembly 
one last thing, is MASM included in visual studio 6.0 or .NET ???
Last edited by ZaidGS; Aug 23rd, 2003 at 04:04 PM.
-
Aug 22nd, 2003, 03:26 PM
#4
Fanatic Member
Depending on how well you program and what is slowing you down, you have a possibility of getting that extra speed.
You might even find a different way of approaching a problem using assembler that overcomes some of the limitations that are inheritantly in the high level language of choice.
MASM is not included with VC++. Personally, I like NASM.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
Aug 26th, 2003, 01:12 AM
#5
Frenzied Member
would assembler speed up a code that looks something like this?:
Code:
for (i=0;0<1000;i++){
//some add's and pow's here.
for (j=0;0<1000;j++){
//some add's and pow's here.
while (k<1000){
//many pow's and other stuff here.
}
//some add's and pow's here.
}
}
my program doesnt look exactly like this, but almost.
i think this is pretty intensive code. lost of calculations.
-
Aug 26th, 2003, 02:20 PM
#6
Fanatic Member
It could, depending on what that disassembles to and how good you are at assembler.
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|