0% found this document useful (0 votes)
27 views5 pages

Chapter 2

Uploaded by

V Kumar
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)
27 views5 pages

Chapter 2

Uploaded by

V Kumar
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/ 5

CHAPTER-2 Instructions – Language of computer

Detailed steps of translation of source program to object code. Assembly language: -Assembly language is a symbolic language that can be
translated into binary machine language.

Pseudo instructions: - A common variation of assembly language instructions


whose appearance in assembly language simplifies translation and programming.
The hardware need not implement pseudo instructions.
E.g. $Zero is a register which has the value 0 always and the programmer cannot
change the value of register $zero.
Thus the MIPS assembler accepts “move” instruction even though it is not found
in the MIPS architecture:
move $t0, $t1 # register $t0 gets register $t1
The assembler converts this assembly language instruction into the machine
language equivalent of the following instruction:
add $t0, $zero, $t1 # register $t0 gets 0 + register $t1

Assembler: -
 Assembler is a translator which turns the assembly language program into an
object file, which is a combination of machine language instructions, data, and
information needed to place instructions properly in memory.
 To produce the binary version of each instruction in the assembly language
program, the assembler must determine the addresses corresponding to all
labels.
 Assemblers keep track of labels used in branches and data transfer instructions
There are four steps in transforming a C program in a file on disk into a program in a symbol table.
running on a computer.  Symbol table: - A table that matches names of labels to the addresses of the
 A high level language program is first compiled into an assembly language memory words that instructions occupy.
program.  The translation process has two major parts.
 Assembler assembled the assembly language program into an object module in The first step is to find memory locations with labels so that the relationship
machine language. between symbolic names and addresses is known when instructions are
 Linker combines multiple modules with library routines to resolve all translated.
reference.  The second step is to translate each assembly statement by combining the
 Loader places the machine code into the proper memory locations for numeric equivalents of opcodes, register specifiers, and labels into a legal
execution by the processor. instruction.
 To speed up the translation process, some steps are skipped or combined.  An assembler’s first pass reads each line of an assembly file and breaks it into
Some compilers produce object modules directly, and some systems use its component pieces. These pieces, which are called lexemes, are individual
linking loaders that perform the last two steps. words, numbers, and punctuation characters.
 For example, the line ble $t0, 100, loop contains six lexemes: the opcode ble,
Compiler: - Compiler is a system software that translates high-level language the register specifier $t0, a comma, the number 100, a comma, and the symbol
statements into assembly language statements. loop.
CHAPTER-2 Instructions – Language of computer
Object file format: -
 The object file header describes the size and position of the other pieces of the
file.
 The text segment contains the machine language code for routines in the
source file. These routines may be unexecutable because of unresolved
references.
 The data segment contains a binary representation of the data in the source file.
The data also may be incomplete because of unresolved references to labels in
other files.
 The relocation information identifies instructions and data words that depend
on absolute addresses. These references must change if portions of the
program are moved in memory.
 The symbol table associates addresses with external labels in the source file
and lists unresolved references.
 The debugging information contains a concise description of the way the
program was compiled, so a debugger can find which instruction addresses
correspond to lines in a source file and print the data structures in readable
form.

Linker: - Loader: -
 A systems program that places an object program in main memory so that it is
 Separate compilation: - Splitting a program across many files, each of which
ready to execute.
can be compiled without knowledge of what is in the other files.
 The loader follows these steps in UNIX systems:
 The tool that merges these files is the linker. It performs three tasks:
1. Reads the executable file header to determine size of the text and data
a) Searches the program libraries to find library routines used by the
segments.
program.
2. Creates an address space large enough for the text and data.
b) Determines the memory locations that code from each module will
occupy and relocates its instructions by adjusting absolute references 3. Copies the instructions and data from the executable file into memory.
4. Copies the parameters (if any) to the main program onto the stack.
c) Resolves references among files.
5. Initializes the machine registers and sets the stack pointer to the first free
 A linker’s first task is to ensure that a program contains no undefined labels.
location.
 The linker produces an executable file that can run on a computer. Typically,
6. Jumps to a start-up routine that copies the parameters into the argument
this file has the same format as an object file, except that it contains no
registers and calls the main routine of the program.
unresolved references or relocation information.
7. When the main routine returns, the start-up routine terminates the program
with an exit system call.
CHAPTER-2 Instructions – Language of computer
Instructions: Language of computer: -  The MIPS architecture is a Reduced Instruction Set Computer (RISC). This
Instructions: - The words of a computer’s language are called instructions means that there are a smaller number of instructions that use a uniform
Instructions set: - An instruction set, or instruction set architecture (ISA), is instruction encoding format.
the part of the computer architecture related to programming, including data types,  MIPS is a load/store architecture, which means that all instructions (other than
instructions, registers, addressing modes, memory architecture, interrupt and the load and store instructions) must use registers as operands (no memory
exception handling, and external I/O. An ISA includes a specification of the set of operands are allowed).
opcodes (machine language), and the native commands implemented by a
particular processor. SPIM: -
 SPIM is a MIPS processor simulator, designed to run assembly language code
MIPS (Microprocessor without interlocked pipeline stages) for this architecture.
 MIPS is one instruction set architecture to illustrate concepts in assembly  SPIM can read and immediately execute assembly language files.
language and machine organization.  SPIM is a self-contained system for running MIPS programs. It contains a
 MIPS is just convenient because it is real, yet simple and primarily in debugger and provides a few operating system–like services.
embedded systems.
 The first MIPS ISA was MIPS I, followed by MIPS II through MIPS V. MIPS Operands: -
 The current ISAs are referred to as MIPS32 (for the 32-bit architecture) and
MIPS64 (for the 64-bit architecture).

Different types of MIPS registers: -


CHAPTER-2 Instructions – Language of computer
 Registers are numbered from 0 to 31
 Each register can be referred to by number or name
 Number references:
$0, $1, $2… $30, $31
 By convention, each register also has a name to make it easier to code
 For now:
$16 - $23$s0 - $s7
$8 - $15$t0 - $t7

Simulation of a virtual machine: -


 The basic MIPS architecture is difficult to program directly because of delayed
branches, delayed loads, and restricted address modes.
 MIPS wisely chose to hide this complexity by having its assembler implement
a virtual machine.
 Virtual machine: - A virtual computer that appears to have non delayed
branches and loads and a richer instruction set than the actual hardware.
 The virtual computer also provides pseudo instructions, which appear as real
instructions in assembly language programs. The hardware, however, knows
nothing about pseudo instructions, so the assembler must translate them into
equivalent sequences of actual machine instructions.

Byte order: -
 Processors can number bytes within a word so the byte with the lowest number System call: -
is either the leftmost or rightmost one.  SPIM provides a small set of operating system–like services through the
 The convention used by a machine is called its byte order. system call (syscall) instruction.
 MIPS processors can operate with either big-endian or little-endian byte  To request a service, a program loads the system call code into register $v0
order. and arguments into registers $a0–$a3 (or $f12 for floating-point values).
 System calls that return values put their results in register $v0 (or $f0 for
floating-point results).

To print a string
li $v0 4
la $a0 strvar
 The name big-endian is used when lower byte addresses are used for the more syscall
significant bytes (the left most bytes) of the word.
 The name little-endian is used for the opposite ordering, where the lower byte To print an integer
addresses are used for the less significant bytes (the right most bytes) of the li $v0 1
word. lw $a0 intvar
syscall
CHAPTER-2 Instructions – Language of computer
To read an integer
li $v0 5
syscall

To end the program


li $v0 10
syscall

To read a string and display the string simultaneously


.data
str: .space 16
.text
.globl main
main:
li $v0 8
li $a0 str
li $a1 16
syscall

li $v0 4
syscall #The value stored in the address of a0 will be displayed.
jr $ra

You might also like