KEMBAR78
Languages of The Computer | PDF | Programming | Computer Program
0% found this document useful (0 votes)
11 views26 pages

Languages of The Computer

Uploaded by

pratyush3703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views26 pages

Languages of The Computer

Uploaded by

pratyush3703
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Introduction to Computing (CS 101)

System Software and Program Execution

T. Venkatesh & John Jose

Department of Computer Science & Engineering


Indian Institute of Technology Guwahati 1
Program Execution

• CPU does the following steps to run a program


(instructions are in machine language).
1. Fetch an instruction
2. Decode the instruction & bring data (if needed)
3. Execute the operation
4. Store the results (if needed)
Running Programs
• Computer goes through different steps to run a program
• The program has to be in machine language and should
be in executable format in the memory to execute

Memory
Machine language
program
(executable file)
Input Data
Data entered CPU
during execution

Computed results
Program Output
Computer Languages
Portable : - Means the same code written can run in any other
system's environment.

• Machine Language (ML)


• Uses binary code
• Machine-dependent
• Not portable

• Assembly Language (AL)


• Uses mnemonics
• Machine-dependent
• Not usually portable

• High-Level Language (HLL)


• Uses English-like language
• Machine independent
• Portable (but must be compiled for different platforms)
• Examples: Pascal, C, C++, Java, Fortran, . . .
Machine Language
• The representation of a computer program which can be
understood by the computer.
• A program in machine code consists of a sequence of
machine instructions.
• Machine instructions are in binary code
• Machine instruction has 2 parts
• Opcode- what is the operation like addition, subtraction, multiplication, and comparision.
• Operand(s) – where to perform the operation oropcode the data on which this
has to be performed.
This data can be memory
ADD R1, R2, R3 [R1 R2+R3] address, number.
registers, or any

1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1 [16 bit instruction]


MOVE R4, R7 [R4 R7]
1111010001110000
JUMPEQ R2, R6 15 [If R2==R6, PC PC+15]
0001001001101111
Assembly Language
• A symbolic representation of the machine language of a
specific processor.
• Is converted to machine code by an assembler.
• Usually, each line of assembly code produces one
machine instruction (One-to-one correspondence).
• Mnemonic representation of the instructions and data
SUB32:- Name of the program
PROC:- defines beginning of any
program
Note:- Contents
CMP:- Compare the value in the b/w PROC
register AX
JL:- Jump if less than AX to done and ENDP is
JG:_ Jump if greater than to done
SUB:- Subtract 32 from AX
termed as body.
DONE:- This marks the end of the
program if the conditons
of CMP,JL,JG are not met.
RET:_ Instruction to return to main program
ENDP:- This marks the end of procedure
SUB32
High-level language
• A programming language which use statements consisting of
English-like keywords such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language
instructions (one-to-many correspondence).
• Much easier to program than in assembly language.
• Data are referenced using descriptive names.
• Operations can be described using familiar symbols. LUI(Load Upper Immediate):- This instruction loads the immediate value 0 into the upper 20 bits of register
R2. It effectively sets the value of R2 to 0. The lower 12 bits of register R2 is set to o.
LUI R3, #3:- This sets the register R3 to 3 using LUI. R3 will be used as a loop counter to control the
number of iterations in the loop.
ADDI(Add Immediate):- This is used to add an immediate value to a register and store in the register. This
has application for running a loop, etc..
ADDI R3, R2, #5 ; This add an immediate value 5 to the contents of the register of R2
and store the value in R3.
LOOP:_- Here loop is a label which are not the instructions but are used as reference point for the branch
instructions that determines whether to repeat the loop or exit it. The label provides a target for the
program to jump back to when it reaches the end of the loop body.
BNEZ(Branch if not equal to zero):- It is a branch instruction.
BNEZ R3, LOOP; here R3 is the source register means whose value is to be
checked.
LOOP:- Here it refers to the label to which the program will jump if the
value in the source register is not equal to zero.
If the value in R3 is zero, the loop is done, and the program proceeds to the next instruction.

100:- offset; R0:- Base register;


The value in register R2 (the accumulated sum) is stored at the memory address calculated as 100 + the value in register RO.
Compiler
Target Program
Source Program Compiler
Errors

Input Target Program Output

• A compiler is a computer program that translates computer


code written in High Level Language (source program) into
Machine language (target program).

SD(Store Doubleword):- It is used to store


64-bit i.e. doubleword value from a register
into memory.
SD offset(base), source

offset: The offset or displacement from the


base address in memory where the data will
be stored.
base: The base register, specifying the base
address in memory.
source: The source register, containing the
data that will be stored in memory.
Phases of Compiler

INTTOREAL:- Converts integers into real

MOVF Id3, R2:- Move the contents of the memory location


id3 into register R2.
MULF #50.0,R2:- Multiply the value in register R2 by 50.0
Program Errors
• Syntax Errors: Syntax errors occur when the structure of your code violates the rules of the programming language.

• Errors in grammar of the language This error is identified during semantical


analysis of phases of compilation.
• Runtime error:
• When there are no syntax errors, but the program can’t
complete execution
• Divide by zero
• Invalid input data
• Logical errors:
• The program completes execution, but delivers incorrect
results
• Incorrect usage of parentheses
• Wrong logic used
Segmentation fault is generated during execution of program rather than compilation of it. It is genetated when the memory
allocation is not in accordance with the hardware of software demands or when inappropriate meory allocation is done.
Interpretation
Source
Program

Interpreter Output

Input

• Interpreter reads line by line, translates code line by line and


executes statements one at a time
• Makes it easier to detect errors but potentially slowing down
the program.
Compilation vs. Interpretation
Compiler Vs. Assembler
• Assembler is a software that converts an assembly
language code to machine code.
• It takes basic computer commands and converts them into
binary code that computer's processor can use to perform
its basic operations.

HLL Program Compiler ML Program

Assembly Assembler ML Program


Language Program
Source, Object and Executable Programs
• Source program
– The form in which a programmer writes a computer
program in some formal programming language.
– Files usually have extension ‘.c’, ‘.cpp’, ‘.java’, ‘.py’
• Object program
– Output from the compiler
– Equivalent machine language translation of the source
program
– Files usually have extension ‘.obj’
• Executable program
– Output from linker/loader
– Machine language program linked with necessary libraries
and other files
– Files usually have extension ‘.exe’
Linker
• A program that pulls other programs together so that they
can run.
• Most programs are very large and consist of several
modules and may need standard libraries. to run.
• The linker pulls everything together, makes sure that
references to other parts of the program (code) are resolved.
• Generation of an executable binary program from a
collection of independently translated source procedures
requires using a linker.
Program – A collection of object files

Each module has its own address space, starting at 0.


Linking and Relocation

After loading but before Linking and Relocation, (.obj)

After Linking and Relocation (.exe)


Binding Time and Dynamic Relocation

Load address changes- Need for dynamic relocation.


Loader
• Loader is a system program that copies the instructions and
date from secondary memory to main memory.

• It brings object program into memory and make it ready for


execution.

Source Object
Object
Program Compiler Loader program
Program ready for
execution

Memory
The extension here
is .obj.
Functions of Loader
• Loading: Loads the object files into the memory of the
computer system.
Memory refers to main memory or primary memory.
• Address Binding: Maps the virtual addresses used in the
object file to physical addresses in the memory. This ensures
that the program can execute correctly in the memory.

• Linking: Performs linking (if linker and loader are single unit),
which involves resolving external references to libraries or
other executable files.

• Relocation: Involves adjusting the program's references to


memory locations based on the actual physical address.

• Memory Management: Manages memory by allocating and


deallocating memory space for the program as needed.
Classifications of Loader
• Compile and go Loader: Source code goes into the
translator, and the object code is loaded into specific location
in memory. Reloading needs re-compilation. Programmer
should know load address before compilation. The object code is not
stored in hard disk.

• Absolute Loader: Loads the object code (output of compiler)


to specified location in memory. This specific memory location
is specified in the program’s object code by compiler. This
location is usually absolute and does not change when the
program is loaded into memory.

• Linking Loader: Performs linking which involves resolving


external references to libraries or other object files and then
loads the single executable file to memory at designated
address.
Classifications of Loader
• Relocating Loader: It loads a program at any memory
location, and then adjusts all memory references in the
program to reflect the new location. This allows the same
program to be loaded into different memory locations without
having to modify the program’s object code.

• Bootstrap Loader: It is a computer program that is


responsible for booting a computer. Loads OS kernel to main
memory and handover the control to OS kernel.
For loading bootstrap loader, there is a separate chip termed as 'boot
program'.
Role of Loader and Linker
Memory
Source
Object
Program Assembler Linker
Program
Object
program
ready for
Executable execution
Code

• Static linking occurs at compilation


time, hence it occurs prior to loading Loader
a program.

• Dynamic linking occurs at run time,


so it occurs after or at the time of the
loading of a program.
Static and Dynamic Linking
• Static linking occurs at compilation time, hence it occurs
prior to loading a program.

• Dynamic linking occurs at run time, so it occurs after or at


the time of the loading of a program.

In static linking, libraries for a


function are included prior to
its execution in the single
executable file by linker and
loader.

In dynamic linking, the librabies


for any used function is loaded
during runtiime in MEMORY by
linker or loader.
Program Execution and System Software
Thanks

26

You might also like