Machine language program is the fastest?

In summary: A compiler is a program that takes an assembly language program and turns it into an executable program.
  • #1
PainterGuy
940
69
hello everyone,:wink:

i read somewhere that machine language program is the fastest when compared to assembly language and high-level languages program.

i don't get it. i think you can say machine language program is already in 'exe' form. but once assembly language program and high-level language programs have been translated into 'exe' programs by the assembler and compiler respectively, then there would be no difference in speed. because machine language program, assembly language program, and high-level program are all in 'exe' form - in the form of 0s and 1s. so they all are going to run at same speed assuming the program is the same. tell me if i make some sense and never forget i am newbie to programming.:tongue:

cheers
 
Technology news on Phys.org
  • #2
A programmer can use an assembler to convert assembly language into any machine language, so there's no difference there. The purpose of high level languages is to reduce the time it takes to program, and to be somewhat indepent of the computer, so that a program can run on different computers, although the operating system will need to be the same or similar. Depending on the the computer's instruction set, and the level of optimization of the compiler, and the type of program, there usually isn't a lot of difference in the the speed of the program.
 
  • #3
rcgldr said:
A programmer can use an assembler to convert assembly language into any machine language, so there's no difference there. The purpose of high level languages is to reduce the time it takes to program, and to be somewhat indepent of the computer, so that a program can run on different computers, although the operating system will need to be the same or similar. Depending on the the computer's instruction set, and the level of optimization of the compiler, and the type of program, there usually isn't a lot of difference in the the speed of the program.

many thanks rcgldr. :approve:

can you tell me what is this optimizasion?

i was thinking perhaps it made different in past when computers has very limited memory and (i have read somewhere) that they were not installed and every time you wanted to run a program you will run it from some original copy available externally. in that case assembly program will be fast because there is no translator available?:confused: do you think what i say is correct? tell me please.

cheers
 
  • #4
PainterGuy said:
Can you tell me what is this optimization
Depends on the language and the computer. For example, an optimizing compiler will try to use the computer's registers for local variables in functions, and well this works will depend on how many registers the computer has. There are other methods used to speed up the code, such as using a branch table instead of a series of compares for a "C" switch case statement if the cases are nearly sequential (I wouldn't expect you to know about branch tables).

I was thinking perhaps it made different in past when computers has very limited memory and (i have read somewhere) that they were not installed and every time you wanted to run a program you will run it from some original copy available externally.
In older computers with limited memory, it was common to have library functions that resided on a hard drive. IBM 1130's used this scheme with their Fortran compiler. The old Mac OS would keep some of the graphics stuff for a program (resource fork) on a disk and read them in as needed. On the old mainframes and eventually home computers, a more general scheme called virtual memory is used.

in that case assembly program will be fast because there is no translator available?
A translator is used for interactive languages, not compiled. APL was one of the early interpreted languages. Basic was a populer interpreted language for early home computers.
 
  • #5
PainterGuy said:
i read somewhere that machine language program is the fastest when compared to assembly language and high-level languages program.

There should really be no difference between machine language and assembly language. Assembly language is basically machine language written using symbols that are somewhat readable by humans, instead of using strings of 0's and 1's. Each executable assembly-language instruction should produce one machine-language instruction. Non-executable assembly-language "instructions" don't produce actual machine language, but do things like bookkeeping for locations of variables, etc.

In principle, a program written in assembly language by a skilled human programmer who knows techniques for doing things optimally on the particular processor being used, can be more efficient than a program written in a high-level language. But that depends both on the skill of the human programmer and the "skill" of the compiler. Over the years, compilers have become more and more sophisticated.
 
  • #6
rcgldr said:
A translator is used for interactive languages, not compiled. APL was one of the early interpreted languages. Basic was a populer interpreted language for early home computers.
Minor quibble - compilers and interpreters are kinds of translators.
 
  • #7
jtbell said:
There should really be no difference between machine language and assembly language. Assembly language is basically machine language written using symbols that are somewhat readable by humans, instead of using strings of 0's and 1's. Each executable assembly-language instruction should produce one machine-language instruction. Non-executable assembly-language "instructions" don't produce actual machine language, but do things like bookkeeping for locations of variables, etc.

That used to be the case, but it's not quite so simple for high performance computer architectures (and that includes modern multi-processor PCs, not just supercomputers). For example the speed may depend on the amount of overlap that is possible between instructions executed in sequence, or between reading and writing data to memory (RAM) and doing calculations inside the CPU.

An assembler might well reorder the instructions from what you wrote, to take the maximum advantage of such things. Of course you COULD write the instructions in the optimum order yourself, provided you knew every detail about what the speed constraints are, but most people don't want to know that much about the hardware, even if they are writing code in assembler.

There are also things like "look-ahead execution", where it can sometimes be faster to start executing instructions along BOTH possible paths after a conditional ("if") instruction, on the basis that doing something that will be only 50% useful saves time compared with doing nothing at all, while you wait for the "if" to finish deciding which branch to take.
 
  • #8
rcgldr said:
A translator is used for interactive languages, not compiled. APL was one of the early interpreted languages. Basic was a populer interpreted language for early home computers.

Mark44 said:
Minor quibble - compilers and interpreters are kinds of translators.

I was trying to keep my explanation simple. In addition to interpreters, there are cases of compilers producing virtual code, like "p code", that requires a real time translator. Some intepreters may use a similar intemediate step of producing virtual code, then using a translator to run the generated virtual code.

This would be different than a typical compiler that produces machine code or in some cases assembly code that is then assembled to produce machine code, where the generated code does not require the overhead of a translator when running.
 
  • #9
many thanks everybody.:approve:

this is defination of interpreter from a book:--
Interpreter is another type of translator used to translate a high-level language program into its equivalent machine language program. It takes one statement of the high-level language program, translates it into machine language ihstructidns, and then executes the resulting machine language instructions immediately. That is, in case of an interpreter, the translation, and execution processes altemate for each statement encountered in the high level
language program. This differs from a compiler that merely translates the entire source program into an object program, and is not involved in its execution. The input to an interpreter is a source program but unlike a compiler, its output is the result of program execution instead of an object program.


i do not get this definition. the compiler i use dev-c++ also executes the compiled code. and further if interpreter translates one statement and then executes it immediately then how does it work? because you need to have entire program code at your hand to do the required job.

the book also mentioned intermediate language compiler and interpreter. from what it says i understand this intermediate compiler and interpreter approach is used in portable software which runs without actually installing on your computer.

and that book also say that linked is used to linked multiple source files which has been created by different users located at different locations. don't you think this is very limited defination of linker. i do not know even if it is correct.

cheers
 
  • #10
PainterGuy said:
this is defination of interpreter from a book:--
Interpreter is another type of translator ...
I do not get this definition. the compiler i use dev-c++ also executes the compiled code.
Dev-c++ is a combined tool set with a common main interface, similer to the old Borland Turbo products, Visual Studio, ... . The tool can run the code directly or it can run it in debugger mode, but that's not the compiler portion of the development tool.

Also some interpreters will convert source code into "tokenized" code as you enter the statements into a function. They may also do this as an intermediate step in interactive (like using a calculator) mode.

and further if interpreter translates one statement and then executes it immediately then how does it work? because you need to have entire program code at your hand to do the required job.
It only needs to store and maintain (update) the variables. It doesn't matter if the code is only translated and executed one operation at a time. In the case of APL and some other interpreters, a program can generate a string of text and then have that text string be operated as a line of code, or a matrix of text strings created and then treated as a function created in real time.

the book also mentioned intermediate language compiler and interpreter
Some compilers or interpreters produce some common object code that is like virtual machine code, which also requires a translator or emulator during run time.

and that book also say that linked is used to linked multiple source files. Which has been created by different users located at different locations. don't you think this is very limited defination of linker.
A compiler or assembler may output object code modules which contains the code and information on how to deal with external references in that code. The the linker takes one or more object modules, resolves the external references into actual addresses or offsets and produces the actual machine or virtual machine code. Normally all of code itself is created by a programmer or team of programmers at a single location, but the libraries are included with the compiler or translator and were made from souce code developed at another location. In some cases even the primary code is developed at multiple locations, depending on the company.
 
  • #11
i do not get this definition. the compiler i use dev-c++ also executes the compiled code. and further if interpreter translates one statement and then executes it immediately then how does it work? because you need to have entire program code at your hand to do the required job.

DevC++ doesn't actually execute the compiled code. It takes your source code and passes it into a compiler (which is a separate program in itself). That compiler generates object code, which it then passes on to a linker (typically another separate program). The linker puts everything together to turn that object code into an executable file. DevC++ then runs that executable.
 
  • #12
Hi everyone, :wink:

First my many thanks to these guys for the help they have give me: rcgldr, jtbell, Mark44, Alehzero, Speedo. Much grateful for this teaching. :approve:

I have no past experience with programming and trying to learn C++ from ground level.

I use DevC++. I assume it has compiler, linker, debugger, editor in one package and they call it an IDE. I have been told it is outdated. But I like for it's little size and having many standard features. And this is enough for a newbie like me!:tongue:

Where can I get an Interpreter software to experiment with? I also like to experiment with Intermediate Intermediate Langauge Compiler and Interpreter, where can I get my hands on?

I need compiler and linker programs separately to play around? Where I can first compile the source code, then using other program can link it.

Will someone help me out here? These programs should be free because I only have intention to play around with them for understanding. Okay waiting for your reply.:uhh:

[Now I have struggled my best to use proper English with all the capitalization and it took more than 30 minutes :mad:]

Cheers
 
  • #13
PainterGuy said:
I use DevC++. I assume it has compiler, linker, debugger, editor in one package and they call it an IDE. I have been told it is outdated. But I like for it's little size and having many standard features. And this is enough for a newbie like me!:tongue:

DevC++ is just the graphical user interface that wraps everything together. As I recall it comes with the mingw compiler set.

See Why you shouldn’t use Dev-C++. There's really no reason to use it when much better free alternatives are readily available.

Where can I get an Interpreter software to experiment with? I also like to experiment with Intermediate Intermediate Langauge Compiler and Interpreter, where can I get my hands on?

C++ is a compiled language. I don't think there are any interpreters for it. You'd need to go with a different language like Java or Python.

I need compiler and linker programs separately to play around? Where I can first compile the source code, then using other program can link it.

You already have a compiler and linker in the version of mingw included with DevC++. You'll just have to read the manual for mingw to find the commands to manually invoke the compiler and linker from a command prompt (haven't used mingw in many years, can't really help you there, sorry).
 
  • #14
PainterGuy said:
I also like to experiment with Intermediate Langauge Compiler and Interpreter, where can I get my hands on?
Intermediate Langauge is (I believe) exclusive to the .NET Framework languages in Microsoft Visual Studio. These languages include C++, C# (pronounced C sharp), and Visual Basic, and maybe a couple of others.

The compiler translates the source code into intermediate language (IL) instructions, and another component, the Just In Time (JIT) compiler translates the IL instructions into machine code for the architectures that are supported, which IIRC include x86, x64, and (maybe) Itanium.

Although it's possible to write code in IL (and I have done so), people don't really do this, so there's not really much reason to learn about it.
PainterGuy said:
[Now I have struggled my best to use proper English with all the capitalization and it took more than 30 minutes :mad:]
Your English is much better than my Italiano!
 
  • #15
The terminology can vary depending upon one's experience in the computing industry. I used work on microprocessor design and this is how we defined it.
  • Machine Language - the actual Ones and Zeros arranged into words which are read by the CPU from memory and executed. This is the only language the CPU cares about. Few people except for hardware people will ever deal with machine language these days. This is lowest level of code available to the programmer. However internal to the CPU, the machine language gets decomposed further into another level called microcode. A knowledgeable person working with machine code can produce some extremely fast code. On some architectures, they can crash the processor and even make it damage itself. All higher level code has to be converted to machine language before the CPU can deal with it.
  • Assembly Language - It's the symbolic representation of the above machine language. It exists because it much easier to read by humans. It does not require an assembler, as it can be hand assembled, but an assembly program, which converts it to machine language, makes it much easier. Assemblers can be sophisticated and rearrange instructions, but this just means it is a better coder than the machine language guy. Technically assembly is a one to one symbolic translation of machine language and to answer the OP, it's no faster. Microprocessor vendors will produce a programming manual which will detail each instruction in assembly form and it's machine language equivalent. Note that assembly language is arbitrary.
  • Compiler - This is a program that converts a high level language to machine language. A single high level instruction can produce hundreds of machine language instructions. Compilers do their job once. If you want the machine language changed, you have to change the high level source code and run the compiler again. Early examples of popular high level languages that were compiled were Cobol and Fortran. "C" became a popular alternative. On simple chips, it's slower than Machine/Assembly. On modern systems compilers are almost mandatory given the complexity the chip architectures. No human can really effectively write in the lower languages now.
  • Interpreter - It is a running program that reads source code statements similar to a compiler, but instead of producing a file of machine language instructions, the instructions are executed in a simulated environment. Basic & Perl are common interpreted languages. Java is a very sophisticated one. Interpreted languages tend to be portable between architectures but as you can guess, much slower. It should be noted the interpreter itself is always a compiled program.
Generally the closer to the hardware, the faster the program.
 
Last edited by a moderator:

1. What is machine language program?

Machine language program is a low-level programming language that is directly understood by the computer's processor. It consists of binary code (0s and 1s) and is the most basic form of programming language.

2. How is machine language program the fastest?

Machine language program is the fastest because it is directly executed by the computer's processor without the need for translation or interpretation. This eliminates any overhead and allows for efficient and quick processing.

3. Can any computer run a machine language program?

Yes, any computer with a processor can run a machine language program. However, since it is specific to each type of processor, the same program may not run on different types of computers.

4. Is machine language program difficult to write?

Yes, machine language program is difficult to write because it requires a deep understanding of the computer's architecture and instructions. It is also very tedious and time-consuming compared to higher-level programming languages.

5. Are there any advantages to using machine language program?

Yes, there are a few advantages to using machine language program. It allows for precise control over the computer's resources and can be used to create highly efficient programs. It is also useful for low-level tasks such as operating system development and device driver programming.

Similar threads

  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
4
Replies
122
Views
13K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
5K
  • Programming and Computer Science
2
Replies
59
Views
7K
  • Programming and Computer Science
Replies
10
Views
2K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top