|
|
This is a painfully complicated process
But fortunately, we have developed tools that help make this process less painful
|
Problem:
|
Humans are not good in machine languages
These specialized languages are called:
|
|
What a machine language program looks like:
10110101 10101111 01010110 10110111 ... |
|
What an assembler language program looks like:
start add x, y <-- one assembler instruction sub x, y <-- one assembler instruction ... ... end |
Each assembler instruction is a mnemonic that corresponds to a unique machine instruction
|
What a high level language program looks like:
main() { if ( x > y ) // One sentence (statement) in a high level prog. lang. { max = x; } else { max = y; } ..... } |
One statement in a high level programming language is usually translated into multiple machine instruction that achieve the effect specified by the statement
Name | Application area |
---|---|
Fortran | Scientific application (FORmula TRANslator) |
Cobol | Business application (COmmon Business Oriented Language) |
C | System application (successor of a language called "B") |
C++ | System application (successor of the language "C") |
Java | General purpose (a simplification of "C++") |
C# | General purpose (another simplification of "C++") |
Perl | Scripting language with many string processing capabilities |
Python | Scripting language using indentation as block denotation. |
As long as neither number is zero (0) do { if ( number on A ≥ number on B ) replace the number on A by the value (A - B) otherwise replace the number on B by the value (B - A) } The Greatest Common Divisor (GCD) of the numbers A and B is the non-zero number on one of the papers |
public class Euclid { public static void main(String args[]) { int A; // Memory cell named "A" int B; // Memory cell named "B" // These memory cells are like the 2 pieces of paper // we used above. They can store and recall a value A = 28; // Write "28" on the piece of paper named "A" B = 36; // Write "36" on the piece of paper named "B" // ================================ // This is the Euclid Algorithm: // ================================ while ( A != 0 && B != 0 ) { if ( A >= B ) A = A - B; // Replace the number on A by (A-B) else B = B - A; // Replace the number on B by (B-A) } System.out.println("GCD = " + B); } } |
Note:
|
How to use this program:
|
|
|
|
|
|
|
E.g.: a very simple program in the C programming language
main() { printf("Hello\n"); } |
cc prog.c |
cc is the command to run the C compiler (translator)
The second word prog.c is the name of the file that contains the C program (that is being translated)
The machine operations that result from the translation process is stored in the file:
a.out |
>> a.out |
Note:
|
How to do the demo:
|
|
|