PROGRAMMING THE COMPUTER - DCClblopes/aulas/ic/T9.pdf · PROGRAMMING THE COMPUTER ... Interpreted...
Transcript of PROGRAMMING THE COMPUTER - DCClblopes/aulas/ic/T9.pdf · PROGRAMMING THE COMPUTER ... Interpreted...
PROGRAMMING THE COMPUTER
• programming languages• syntax and semantics• compiler/interpreter• assembler• linker• object file (*.o)• executable file (a.out)• loader• process• process address space
Topics
a programming language is a formal language that specifies a set of instructions that can be used to create
programs that implement specific algorithms.
Calculate max(a,b,c)
PROGRAMMING LANGUAGES
Important Aspects of a Program
syntax: is the program written according to the programming language grammar?
e.g., int if = 2;
semantics: is the program well formed?
e.g., int x = 2, y = 5; float z = x + y;
• compiler takes entire program as input
• full program is checked for errors
• requires more memory
• program is compiled once
• e.g., C, C++, Java
Compiled Languages
• interpreter takes each instruction as input
• instruction (only) is checked for errors
• instruction is executed at once
• less memory required
• program is interpreted everytime
• e.g., Bash, Python, Ruby
Interpreted Languages
Ca compiled language
case study #1
original (source) code in C
intermediate code (assembly
representation)MIPS R2000
native code (binary)
MIPS R2000
compilers transform source code into valid/executable binary code
instructions and data translated into binary sequences, the only language
understood by microprocessors
only some binary sequences are valid/executable
the same source program is compiled into different binary sequences for different microprocessors, e.g., Intel x86 or ARM
binary code is hardware dependent, source code is not
Compiling a C program
Basic compilation steps
Linking object file with libraries
• checks the object file to identify required missing binary code
• searches other object files and operating system libraries for those pieces of code
• determines in which position they must be inserted in the object file and adjusts references
• produces executable file (or fails)
The Program Linker
a program becomes a process
The Program Loader(part of the operating system)
• creates an address space in main memory large enough to hold the program, a heap and a stack
• copies the code and data of the program to the address space, and the command line arguments to the stack
• initialises register values including the stack pointer and the program counter
• the original program is now ready to run and is called a process
• this happens when you click on an application icon in the Desktop
• or, when you execute a program directly from the command shell as in:
$./a.out