Need help with compiler and language choices

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Need help with compiler and language choices

Post by Don »

I think assembly is easier to learn than C with it's many dark corners. Assembly may be very primitive, but it's very straightforward. It appears very intimidating at first but that's just an illusion.

It will of course take longer to write a chess program in assembly but it's not as bad as it's often made out to be.

It would be a pain doing some things in assembly but chess programs are mostly composed of simple logic - you don't need to learn the API's of lot's of external libraries for instance to write a chess program.

Of course portability is a huge disadvantage and the fact that you probably won't even end up with a faster program unless you know what you are doing. I'm not recommending assembly, but I'm pointing out that it's not incredibly difficult to write - contrary to popular opinion.


Greg Strong wrote:There's a whole spectrum from most primitave to most abstract... Most chess programs are C or C++. When you asked, the recomendations were in the C, C++, C# range. You then went even further in the abstract direction and asked about Visual Basic. Now you're going all the way in the other direction and asking about assembly? Don't get me wrong, I'm not trying to disuade you from any well-informed choice, but why on earth would you want to go all the way from one extreme to the other? Assembly would be incredibly hard to write, hard to debug, not portable, and given how strong compiler optimization is these days, it's not even clear that such code would be faster. May I respectfully suggest that you consider C, C++, or C# instead. Otherwise, you'll need at least a year of full-time dedication to even get to the point of a fully-functioning chess program, and it won't be portable.

On the other hand, it's a hobby, and if that's what's fun for you, I wouldn't want to discourage you. Just want you to be realistic about what you're getting into ...
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Need help with compiler and language choices

Post by Greg Strong »

You are saying that Intel assembly language is easier to learn than C?
mhalstern
Posts: 484
Joined: Wed Nov 18, 2009 1:09 am

Re: Need help with compiler and language choices

Post by mhalstern »

Your statement about the "black art." is correct. I am good at google searches and general internet research, and was unalbe to find any information.

I found the link to download MSAM. I'll take a look unless I find a better tool.
Last edited by mhalstern on Sun Mar 28, 2010 6:31 am, edited 1 time in total.
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Need help with compiler and language choices

Post by Don »

mhalstern wrote:Don,

With Rexchess, what did you use to get make an executable from the assembler code? What tools are available for the windows 7 64 bit envrionment?

I'd like to play around with assembler.

Thanks
I did this a long time ago but it was easy to pick up and learn. You need something that is called an assembler. I do not know what is available for windows. An assembler is much higher level than pure "machine code" because it does a lot of things for you. For instance you can define a chunk of memory to use as an array and not have to think about the address of the memory or tracking the endpoint. In assembler (or even C) a variable is just a memory location and in assembler you think of it more as a memory location but still refer to it with a label.

In a lot of ways C is like a super fancy assembler but it's not really an assembler because you don't have to think about registers and stacks as much. You will probably be happier with C if you want to go low level like this.
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Need help with compiler and language choices

Post by Don »

Greg Strong wrote:You are saying that Intel assembly language is easier to learn than C?
Yes, at least it was for me.

It was easier for me because when I learned C I was constantly tripping over the syntax, figuring out the libraries, etc. It's just a LOT to learn. It took a while before it was second nature to me and now I rarely refer to a manual - but that initial learning curve is steep.

But assembly is very regular and hardly has any syntax. You learn a few op-codes and what they do are very precisely defined and you are writing code very quickly.

However, it could be more difficult to learn than C if you don't already have a good understanding of how data is stored in a computer and how basic operations such as and, or, xor and things like this work.
mhalstern
Posts: 484
Joined: Wed Nov 18, 2009 1:09 am

Re: Need help with compiler and language choices

Post by mhalstern »

Please correct me if my thoughts are not correct:

I understand that with all of the modern "optimized" compilers and Profile Guided Optimization (POGO), writing an engine in C or C++ may be more efficient than something that I would write in assembler, but I would prefer to be responsible for exactly what I attempted to output.

I am worried that a new "smart" compiler will effectively change some parts of my code. Presumably, If I create an executable from assembler, I will have more control, and will be able to learn more.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Need help with compiler and language choices

Post by jwes »

mhalstern wrote:Please correct me if my thoughts are not correct:

I understand that with all of the modern "optimized" compilers and Profile Guided Optimization (POGO), writing an engine in C or C++ may be more efficient than something that I would write in assembler, but I would prefer to be responsible for exactly what I attempted to output.

I am worried that a new "smart" compiler will effectively change some parts of my code. Presumably, If I create an executable from assembler, I will have more control, and will be able to learn more.
You will definitely have more control, and you will need to learn many new things, though most of them will have little to do with chess. To write assembler code that is competitive with the best C compiled code, you will need to learn much more about processor details than most people want to.
The classic approach to this is to write your program in a high level language, profile the code, and then see if you can speed up the program by writing some small part of it in assembler. Many compilers have an option to output assembler code which is useful to see how to interface your assembler code to the rest of your program and the operating system.
User avatar
jshriver
Posts: 1358
Joined: Wed Mar 08, 2006 9:41 pm
Location: Morgantown, WV, USA

Re: Need help with compiler and language choices

Post by jshriver »

A great and open source assembler for x86 is nasm. I've been using it off/on since the mid 90's and works well in Windows or Linux and supports various object formats including flat binary.

Had originally used it to write my own bootstrap loader for an embedded system I was working on.
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Need help with compiler and language choices

Post by Don »

jshriver wrote:A great and open source assembler for x86 is nasm. I've been using it off/on since the mid 90's and works well in Windows or Linux and supports various object formats including flat binary.

Had originally used it to write my own bootstrap loader for an embedded system I was working on.
I saw your post which disappeared but I agree with you on this. High level concepts sometimes take some effort to wrap your brain around - although they seem easy once you have done that. assembly has only very simple concepts so it's very easy to learn quickly.

I would point out that in ANY language being really proficient takes a lot of effort and I don't think that varies so much regardless of the language. Whether it's C, assembly, or kung-fu you probably won't be a black-belt for quite some time.
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Need help with compiler and language choices

Post by jwes »

Don wrote:
jshriver wrote:A great and open source assembler for x86 is nasm. I've been using it off/on since the mid 90's and works well in Windows or Linux and supports various object formats including flat binary.

Had originally used it to write my own bootstrap loader for an embedded system I was working on.
I saw your post which disappeared but I agree with you on this. High level concepts sometimes take some effort to wrap your brain around - although they seem easy once you have done that. assembly has only very simple concepts so it's very easy to learn quickly.

I would point out that in ANY language being really proficient takes a lot of effort and I don't think that varies so much regardless of the language. Whether it's C, assembly, or kung-fu you probably won't be a black-belt for quite some time.
Writing good assembler is a lot harder than it used to be (back when instruction time was a meaningful concept). Now you can spend as much time on instruction sequencing and code location as you do on algorithms.