COD Unit-2 (CH 3) (E-Next - In)
COD Unit-2 (CH 3) (E-Next - In)
UNIT- 2
Memory Hierarchy
https://E-next.in
COD Unit-2
5. It normally stores system programs, instruction and data files. It is also known as
secondary memory.
6. It can also be used as an overflow/virtual memory in case the main memory capacity has
been exceeded.
7. Secondary memories cannot be accessed directly by a processor. First the
data/information of auxiliary memory is transferred to the main memory and then that
information can be accessed by the CPU.
8. The secondary storage devices are:
a. Floppy Disks
b. Magnetic (Hard) Disk
c. Magnetic Tapes
d. Pen Drive
e. Optical Disk(CD,DVD)
Reusable − The data stays in the secondary storage on permanent basis until it is not
overwritten or deleted by the user.
Convenience − With the help of a computer software, authorized people can locate and
access the data quickly.
Capacity − Secondary storage can store large volumes of data in sets of multiple disks.
Cost − It is much lesser expensive to store data on a tape or disk than primary memory.
B. PRIMARY MEMORY(MAIN MEMORY):
1. The main memory occupies the central position because it is equipped to communicate
directly with the CPU and with auxiliary memory devices through Input/output processor
(I/O).
2. Primary memory is internal memory of the computer. It is also known as main memory
and Temporary memory .
3. Primary Memory holds the data and instruction on which computer is currently working.
4. Primary Memory is nature volatile. It means when power is switched off it lost all data.
https://E-next.in
COD Unit-2
1. RAM
2. ROM
a) Static RAM-
Static RAM also known as SRAM ,retain stored information as long as the
power supply is ON.
SRAM are of higher coast and consume more power .
They have higher speed than Dynamic RAM
b) Dynamic RAM–
Dynamic RAM also known as DRAM, its stored information in a very short
time (a few milliseconds) even though the power supply is ON.
The Dynamic RAM are cheaper and moderate speed and also they consume
less power.
https://E-next.in
COD Unit-2
Primary memory devices are more expensive Secondary memory devices are less expensive
4
than secondary storage devices when compare to primary memory devices
The memory devices used for primary memory The secondary memory devices are magnetic
5
are semiconductor memories and optical memories
Primary memory is also known as Main Secondary memory is also known as External
6
memory or Internal memory memory or Auxiliary memory
Examples: RAM, ROM, Cache memory, Examples: Hard Disk, Floppy Disk, Magnetic
7
PROM, EPROM, Registers etc Tapes etc
C. CACHE MEMORY:
A Cache (Pronounced as “cash”) is a small and very fast temporary storage memory.
It is designed to speed up the transfer of data and instructions. It is located inside or close
to the CPU chip.
It is faster than RAM and the data/instructions that are most recently or most frequently
used by CPU are stored in cache.
The data and instructions are retrieved from RAM when CPU uses them for the first time.
A copy of that data or instructions is stored in cache. The next time the CPU needs that
data or instructions, it first looks in cache.
If the required data is found there, it is retrieved from cache memory instead of main
memory. It speeds up the working of CPU.
https://E-next.in
COD Unit-2
D. REGISTER MEMORY:
In a computer, the Memory Address Register (MAR) is the CPU register that either
stores the memory address from which data will be fetched from the CPU, or the address
to which data will be sent and stored.
In general, MAR is a parallel loadregister that contains the next memory address to be
manipulated.
WORD SIZE:
https://E-next.in
COD Unit-2
a) BIG ENDIAN:
When the byte address are stored from left to right side then it is known as Big Endian.
In big endian machines, first byte of binary representation of the multi-byte
data-type is stored first.
Big-endian is an order in which the "big end" (most significant value in the
sequence) is stored first (at the lowest storage address).
In Big-Endian, Most-Significant-Byte (MSB) is stored at lowest address
For example, in a big-endian computer, the two bytes required for
the hexadecimal number 4F52 would be stored as 4F52 in storage (if 4F is
stored at storage address 1000, for example, 52 will be at address 1001).
b) LITTLE ENDIAN:
When the byte address is stored from right to left it is called ad Little endian.
In little endian machines, last byte of binary representation of the multi-byte
data-type is stored first.
Little-endian is an order in which the "little end" (least significant value in the
sequence) is stored first.
In Little-Endian, Least-Significant-Byte (LSB) is stored at lowest address.
In a little-endian system, it would be stored as 524F (52 at address 1000, 4F at
1001).
https://E-next.in
COD Unit-2
INSTRUCTION SET:
Hardware designers invent numerous technologies & tools to implement the desired
architecture in order to fulfill these needs.
Hardware architecture may be implemented to be either hardware specific or software
specific, but according to the application both are used in the required quantity.
As far as the processor hardware is concerned, there are 2 types of concepts to implement
the processor hardware architecture.
First one is RISC and other is CISC.
The CISC approach attempts to minimize the number of instructions per program,
sacrificing the number of cycles per instruction.
Computers based on the CISC architecture are designed to decrease the memory cost.
Because, the large programs need more storage, thus increasing the memory cost and
large memory becomes more expensive.
To solve these problems, the number of instructions per program can be reduced by
embedding the number of operations in a single instruction, thereby making the
instructions more complex.
MUL loads two values from the memory into separate registers in CISC.
CISC uses minimum possible instructions by implementing hardware and executes
operations.
https://E-next.in
COD Unit-2
RISC (Reduced Instruction Set Computer) is used in portable devices due to its power
efficiency.
For Example, Apple iPod and Nintendo DS. RISC is a type of microprocessor
architecture that uses highly-optimized set of instructions.
RISC does the opposite, reducing the cycles per instruction at the cost of the number of
instructions per program Pipelining is one of the unique feature of RISC.
It is performed by overlapping the execution of several instructions in a pipeline fashion.
It has a high performance advantage over CISC.
RISC processors take simple instructions and are executed within a clock cycle
https://E-next.in
COD Unit-2
https://E-next.in
COD Unit-2
RISC functions use only a few parameters, and the RISC processors cannot use the call
instructions, and therefore, use a fixed length instruction which is easy to pipeline.
The speed of the operation can be maximized and the execution time can be minimized.
Very less number of instructional formats, a few numbers of instructions and a few
addressing modes are needed.
Mostly, the performance of the RISC processors depends on the programmer or compiler
as the knowledge of the compiler plays a vital role while changing the CISC code to a
RISC code
While rearranging the CISC code to a RISC code, termed as a code expansion, will
increase the size. And, the quality of this code expansion will again depend on the
compiler, and also on the machine’s instruction set.
The first level cache of the RISC processors is also a disadvantage of the RISC, in which
these processors have large memory caches on the chip itself. For feeding the
instructions, they require very fast memory systems.
The performance of the machine slows down due to the amount of clock time taken by
different instructions will be dissimilar
Only 20% of the existing instructions is used in a typical programming event, even
though there are various specialized instructions in reality which are not even used
frequently.
The conditional codes are set by the CISC instructions as a side effect of each instruction
which takes time for this setting – and, as the subsequent instruction changes the
condition code bits – so, the compiler has to examine the condition code bits before this
happens.
Addressing Modes:
Addressing modes are the manner in the data is accessed.
Depending upon the type of instruction applied, addressing modes are of various types
such as direct mode where straight data is accessed or indirect mode where the location
of the data is accessed.
https://E-next.in
COD Unit-2
https://E-next.in
COD Unit-2
In the direct addressing mode, the instruction will have the two parts. One part will
contain the opcode and another one will contain the address of the memory
location at where the operand can be found.
Here A is the address of the operand. That means at the Ath location in the memory,
the operand can be found.
https://E-next.in
COD Unit-2
Here A contains the address of the location B in memory and B contains the actual
address of the operand in memory.
https://E-next.in
COD Unit-2
Advantage:
i) Shorter instructions and faster instruction featch.
ii) Faster memory access to the operand.
Disadvantages:
i) Very limited address space
ii) Using multiple registers help performance but it complicates the
instructions.
Suppose in memory, the operand is in the Ath location. Now, this address A will be
stored in the register and the register number say R will be mentioned in the
instruction.
This is called register addressing mode.
MACHINE LANGUAGE
Machine code, also known as machine language, is the elemental language of computers.
It is read by the computer's central processing unit (CPU), is composed of
digital binarynumbers and looks like a very long sequence of zeros and ones.
https://E-next.in
COD Unit-2
Depending upon the processor, a computer's instruction sets may all be the same length,
or they may vary, depending upon the specific instruction.
The architecture of the particular processor determines how instructions are patterned.
The execution of instructions is controlled by firmware or the CPU's internal wiring.
Human programmers rarely, if ever, deal directly with machine code anymore.
If developers are debugging a program at a low level, they might use a printout that
shows the program in its machine code form.
The printout, which is called a dump, is very difficult and to work with a tool called a
dump.
Utility programs used to create dumps will often represent four bits by a
single hexadecimal to make the machine code easier to read and contain other
information about the computer's operation, such as the address of the instruction that
was being executed at the time the dump was initiated.
https://E-next.in
COD Unit-2
ASSEMBLY LANGUAGE
Each personal computer has a microprocessor that manages the computer's arithmetical,
logical, and control activities.
Each family of processors has its own set of instructions for handling various operations
such as getting input from keyboard, displaying information on screen and performing
various other jobs.
These set of instructions are called 'machine language instructions'.
A processor understands only machine language instructions, which are strings of 1's and
0's.
However, machine language is too obscure and complex for using in software
development.
So, the low-level assembly language is designed for a specific family of processors that
represents various instructions in symbolic code and a more understandable form.
https://E-next.in
COD Unit-2
It is most suitable for writing interrupt service routines and other memory resident
programs.
Types of Assembly Languages
Assembly language closely tied to processor architecture. At least four main types:
CISC: Complex Instruction-Set Computer.
RISC: Reduced Instruction-Set Computer.
DSP: Digital Signal Processor.
VLIW: Very Long Instruction Word.
ASSEMBLER
An assembler is a program that converts assembly language into machine code. It takes
the basic commands and operations from assembly code and converts them
into binary code that can be recognized by a specific type of processor.
Assemblers are similar to compilers in that they produce executable code.
However, assemblers are more simplistic since they only convert low-level code
(assembly language) to machine code.
Since each assembly language is designed for a specific processor, assembling a program
is performed using a simple one-to-one mapping from assembly code to machine code.
Compilers, on the other hand, must convert generic high-level source code into machine
code for a specific processor.
Most programs are written in high-level programming languages and are compiled
directly to machine code using a compiler.
https://E-next.in
COD Unit-2
However, in some cases, assembly code may be used to customize functions and ensure
they perform in a specific way.
Therefore, IDEs often include assemblers so they can build programs from both high and
low-level languages.
INSTRUCTIONS:
Types Of Instruction:
1. Arithmetic Instructions
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as
addition, subtraction and a few more. In 8085 microprocessor, the destination operand is
generally the accumulator. In 8085 microprocessor, the destination operand is generally the
accumulator.
https://E-next.in
COD Unit-2
2. Logic Instruction: The processor instruction set provides the instructions AND, OR, XOR,
TEST, and NOT Boolean logic, which tests, sets, and clears the bits according to the need of
the program.
Operand1: 0101
Operand2: 0011
----------------------------
After AND -> Operand1: 0001
The OR Instruction
https://E-next.in
COD Unit-2
For example,
Operand1: 0101
Operand2: 0011
----------------------------
After OR -> Operand1: 0111
For example,
Operand1: 0101
Operand2: 0011
----------------------------
After XOR -> Operand1: 0110
XORing an operand with itself changes the operand to 0. This is used to clear a register.
For example,
https://E-next.in
COD Unit-2
Shift Instruction:
In computer science, a logical shift is a bitwise operation that shifts all the bits of its
operand.
The two base variants are the logical left shift and the logical right shift.
This is further modulated by the number of bit positions a given value shall be shifted,
such as shift left by 1 or shift right by n.
Unlike an arithmetic shift, a logical shift does not preserve a number's sign bit or
distinguish a number's exponent from its significand (mantissa); every bit in the operand
is simply moved a given number of bit positions, and the vacant bit-positions are filled,
usually with zeros, and possibly ones (contrast with a circular shift).
A logical shift is often used when its operand is being treated as a sequence of bits
instead of as a number.
Logical shifts can be useful as efficient ways to perform multiplication or division of
unsigned integers by powers of two.
Shifting left by n bits on a signed or unsigned binary number has the effect of multiplying
it by 2n. Shifting right by n bits on an unsigned binary number has the effect of dividing it
by 2n (rounding towards 0).
Logical right shift differs from arithmetic right shift. Thus, many languages have
different operators for them.
For example, in Java and JavaScript, the logical right shift operator is >>>, but the
arithmetic right shift operator is >>.
(Java has only one left shift operator (<<), because left shift via logic and arithmetic have
the same effect.)
Example
If the bit sequence 0001 0111 (decimal 23) is logically shifted by one bit position, then:
https://E-next.in
COD Unit-2
INSTRUCTION SET:
The instruction set, also called instruction set architecture (ISA), is part of a computer
that pertains to programming, which is basically machine language.
The instruction set provides commands to the processor, to tell it what it needs to do.
The instruction set consists of addressing modes, instructions, native data types, registers,
memory architecture, interrupt, and exception handling, and external I/O.
An example of an instruction set is the x86 instruction set, which is common to find on
computers today.
Different computer processors can use almost the same instruction set while still having
very different internal design.
Instruction Cycle;
The instruction set, also called instruction set architecture (ISA), is part of a computer that
pertains to programming, which is basically machine language. The instruction set provides
commands to the processor, to tell it what it needs to do. The instruction set consists of
addressing modes, instructions, native data types, registers, memory architecture, interrupt, and
exception handling, and external I/O.
https://E-next.in
COD Unit-2
An example of an instruction set is the x86 instruction set, which is common to find on
computers today. Different computer processors can use almost the same instruction set while
still having very different internal design. Both the Intel Pentium and AMD Athlon processors
use nearly the same x86 instruction set. An instruction set can be built into the hardware of the
processor, or it can be emulated in software, using an interpreter. The hardware design is more
efficient and faster for running programs than the emulated software version.
https://E-next.in