Unit-1 PCD
Unit-1 PCD
Unit-1 PCD
Assembler:
An assembler is a program that translates each instruction to its binary machine code
equivalent.
It is a relatively simple program.
There is a one-to-one or near one-to-one correspondence between assembly language
instructions and machine language instructions.
Scanning (tokenizing)
Parsing (validating the instructions)
Creating the symbol table
A single pass assembler scans the program only once and creates the equivalent binary
program.
The assembler substitute all of the symbolic instruction with machine code in one pass.
Advantages every source statement needs to be processed once.
Disadvantages we cannot use any forward reference in our program. Forward Reference
Forward reference means; reference to an instruction which has not yet been encountered
by the assembler.
In order to handle forward reference, the program needs to be scanned twice. In other
words a two pass assembler is needed.
JMP LATER
...
...
LATER:
Dr. Neeraj Dahiya, Asst. Prof., CSE Page 2
This is known as a forward reference. If the assembler is processing the file one line at a
time, then it doesn't know where LATER is when it first encounters the jump instruction.
So, it doesn't know if the jump is a short jump, a near jump or a far jump. There is a large
difference amongst these instructions. They are 2, 3, and 5 bytes long respectively. The
assembler would have to guess how far away the instruction is in order to generate the
correct instruction.
If the assembler guesses wrong, then the addresses for all other labels later in the program
would be wrong, and the code would have to be regenerated. Or, the assembler could
always choose the worst case.
But this would mean generating inefficiency in the program, since all jumps would be
considered far jumps and would be 5 bytes long, where actually most jumps are short
jumps, which are only 2 bytes long.
Macros:
CLASSIFICATION OF MACROS:
Lexical expansion:
Semantic expansion:
The use of a macro name with a set of actual parameters is replaced by some code
generated from its body is called macro expansion.
A program that translates assembly language instructions into machine code and which
the programmer can use to define macro instructions.
Comments
Labels
Addressing modes
Arithmetic Expressions
Comments:
Any texts after all operands for a given mnemonic have been processed.
A line beginning with * (in the first column) up to the end of the line.
An empty line.
Labels:
The Assembler has the facility to generate symbolic labels during assembly process.
The Assembler will iden3fy what addressing mode each instruc3on is in, and assigns the
appropriate opcode.
Arithmetic Expressions:
The Motorola assembler supports several arithme3c opera3ons which can be used to form
values of labels or instruction arguments.
Addition +
Subtraction –
Multiplication *
Division /
Remainder after division %
Bitwise AND &
Bitwise OR |
Bitwise XOR ^
Loader:
It is a SYSTEM PROGRAM that brings an executable file residing on disk into memory
and starts it running.
STEPS:
Read executable file’s header to determine the size of text and data segments.
Create a new address space for the program.
Copies instructions and data into address space.
Copies arguments passed to the program on the stack.
Initializes the machine registers including the stack pointer.
Jumps to a startup routine that copies the program’s arguments from the stack to
registers and calls the program’s main routine.
Bootstrap Loader:
When a computer is first tuned on or restarted, a special type of absolute loader, called
bootstrap loader is executed
This bootstrap loads the first program to be run by the computer -- usually an operating
system.
The bootstrap itself begins at address 0.
Static Linking:
Static linking occurs when a calling program is linked to a called program in a single
executable module.
When the program is loaded, the operating system places into memory a single file that
contains the executable code and data.
Advantage:
Static linking is that you can create self-contained, independent programs.
In other words, the executable program consists of one part (the .EXE file) that you
need to keep track of.
Disadvantages:
You cannot change the behavior of executable files without relinking them.
Dynamic Linking: