Not understanding how software works.

I have been programming for about two years (C/C++, Java, C#). I feel that I have gotten pretty decent in these languages. I have now started college and a question that I've had for a while has now arisen again. It all started when I was reading this (boring) Intro. Programming logic book for my first semester in college. The book reminded me that CPU's run on different machine level instruction sets and, I was wondering how is it possible that I can program an application on a pc with an AMD cpu and it work on a pc with an Intel cpu? Also if programs are compiled down to machine language why aren't all programs cross-platform? Note: I understand how Java works since it has its JVM.
I put this in the beginners section because I assume its a pretty simple answer.
Maybe this will help you to understand; a quote from a section on this site.

Programming languages
A programming language is a set of instructions and a series of lexical conventions specifically designed to order computers what to do.

When choosing a programming language to make a project, many different considerations can be taken. First, one must decide what is known as the level of the programming language. The level determines how near to the hardware the programming language is. In the lower level languages, instructions are written thinking directly on interfacing with hardware, while in "high level" ones a more abstract or conceptual code is written.

Generally, high level code is more portable, that means it can work in more different machines with a smaller number of modifications, whereas a low level language is limited by the peculiarides of the hardware which it was written for. Nevertheless, the advantage of low level code is that it is usually faster due to the fact that it is indeed written taking advantage of the possibilities of a specific machine.

A higher or lower level of programming is to be chosen for a specific project depending on the type of program that is being developed. For example, when a hardware driver is developed for an operating system obviously a very low level is used for programming. While when big applications are developed usually a higher level is chosen, or a combination of critic parts written in low level languages and others in higher ones.


Although there are languages that are clearly thought to be low level, like Assembly, whose instruction sets are adapted to each machine the code is made for, and other languages are inherently high level, like the Java, that is designed to be totally independent of the platform where is going to run. The C++ language is in a middle position, since it can interact directly with the hardware almost with no limitations, and can as well abstract lower layers and work like one of the most powerful high level languages.


Take more notice of the paragraphs in italics.
So higher level programming languages interact more with the Operating System and, lower level programming languages interact more with the physical devices. Thanks mcleano
I was wondering how is it possible that I can program an application on a pc with an AMD cpu and it work on a pc with an Intel cpu?

That is because AMD CPUs are using the x86 instruction set.

Also if programs are compiled down to machine language why aren't all programs cross-platform?

Because besides the fact that the program can only work on the particular CPU architecture it was compiled for, programs have to depend on various functions of the operating system, since modern operating systems don't allow direct hardware access. Besides, reimplementing access to various hardware, file systems and various other things for every program would get old quickly, so you'd use functions provided by the OS (=platform-specific) and other libraries voluntarily anyway.
Topic archived. No new replies allowed.