You are on page 1of 5

CS1FC16 DATA MANIPULATION

Data manipulation refers to moving data from one location to another, as well as performing operations,
such as arithmetic and logic calculations.

Computer architecture

A digital computer usually consists of an interconnected system of processors, memories and


input/output devices.
CPU – central processing unit consists of:
 Arithmetic/logic unit – performs operations on data
 Control unit – coordinates machine's activities
 Register unit – contains data storage cells that are used for temporary storage of information
within the CPU
o General purpose registers – act as a temporary storage for data being manipulated.
They hold the input for ALU and provide place for the results. Data from main memory is
first moved into the registers and from there it goes to the ALU. The registers are not
addressed as memory locations would be, but manipulated directly by the control unit

o Special purpose registers


CPU and main memory are connected by a bus through which the CPU can read and write data at a
particular address in main memory.
Example: to add 2 numbers from the main memory:

o Get the values from the main memory and place them in the register
o Perform the operation
o Place the result into main memory

*Many machines contain cache memory – located in the CPU – to avoid frequent data transfers
between CPU and main memory

Stored-program concept

The idea of storing a computer's program in main memory – von Neumann architecture is built upon this
concept.

Historical background:
Early computers were very inflexible – things they could do were built into the control units.
Some were designed so that the CPU could be rewired – allowing for a little more flexibility. A
breakthrough came with the realization that a program can be stored in the main memory just
like data – in this way the control unit can extract the program from main memory – to change
what we want the computer to do we simply need to change the content of main memory
instead of having to rewire the CPU. Stored-program concept is the standard approach used
today. Originally it was difficult for people to understand as they thought of programs and data
as two different entities – with data stored in the memory and programs as parts of the CPU.

Main memory organization

The main memory is a temporary storage where running programs and data are stored.

Also called random access memory (RAM) - it is organized as individual cells that can be accessed
randomly and independently of each other. RAM can be static (SRAM) or dynamic (DRAM).

Main memory consists of a number of cells, each of which can store a piece of information. Each cell has
a unique address to which the program can refer in execution

Memory cell – a storage space of n bits which can hold 2 n different bit combinations. Almost all
computers have 8-bit cells, although in theory they can be of any size.

Each memory cell has an address – a number uniquely identifying the cell in the main
memory. The addresses are numbers assigned consecutively, starting at 0. Address
space is the range of possible addresses. It is determined by the number of bits used to
represent the address.
The memory cells are normally envisioned as being arranged in a row. The left end of this row is called
high-order end, whereas the right end is called low-order end.
An important consequence of assigning an order to both the cells in main memory and the bits within
each cell is that the entire collection of bits is essentially ordered in one long row. Parts of this row can
therefore store bit patterns longer that the content of an individual cell.

Secondary storage
Due to the volatility(data loaded into RAM disappear as the computer is shut down) and limited size of
the main memory, most computers have additional memory devices called mass storage or secondary
storage.

Memory space measures:


Kilobyte(KB) - 210 = 1024 bytes
Megabyte(MB) = 220 bytes
Gigabyte(GB) = 230 bytes

A byte is 8 bits. Bytes are grouped into words and stored in main memory and registers
In 32-bit architecture a word is 4 bytes.
In 64-bit architecture a word is 8 bytes.
Example: if a word is 32 bits, we require 4 8-bit cells to store it. Suppose the word is 90AB12CD16 - 2 digit
in hex is one byte. There are two ways to store this word:
Big endian – the most significant byte is stored in the smallest address:
Cell 1 – 90
Cell 2 – AB
Cell 3 – 12
Cell 4 – CD
Little endian – the least significant byte is stored in the smallest address:
Cell 1 – CD
Cell 2 – 12
Cell 3 – AB
Cell 4 – 90

Machine instructions

A program encoded as bit patterns and stored in main memory is called instructions. The CPU can
extract the instructions from main memory and execute them.
A machine language is a set of machine instructions along with the encoding system. An instruction
expressed in a machine language is a machine-level instruction.

A list of instructions a typical CPU must be able to decode and execute is quite short. Once a machine
can perform certain elementary tasks, adding more features does not increase machine's fundamental
capabilities.

There are 2 types of CPU architecture:


 RISC – reduced instruction set computer
o CPU designed to execute a minimal set of machine instructions
o Machine is efficient, fast and less expensive to manufactured
o Example: PowerPC from Apple/IBM/Motorola
 CISC – complex instruction set computer
o CPU with an ability to execute a large number of complex instructions, even though
many of them are technically redundant
o The machine can exploit a powerful set of instructions, many of which would require a
multi-instruction sequence in RISC design
o More complex CPU can better cope with the ever-increasing complexity of today's
software
o Example: Intel

Architecture associated with operations


Machine instructions can be categorized into 3 groups:
 Data transfer – instructions to copy data from one location to another.
o LOAD – transfer from main memory to general purpose register
o STORE – transfer from general purpose register to main memory
o Input/output instructions
 Arithmetic/logic - instructions to request activity in ALU
o Arithmetic operations – addition, subtraction, multiplication, division (precise actions
depend on whether the values are stored as floating points or 2's complement
o Logic operations – AND, OR, XOR – to combine 2 strings of bits, the basic operation is
applied to individual columns
o rotation and shift operation – a means for moving bits within a register
 Circular shift/rotation - the content of a register is shifted one bit in one way,
the bit that falls of is put in the empty space at the opposite end
 Logical shift – the bit that falls of is discarded, the empty space on the opposite
side is filled with 0
 Shifting to the left corresponds to multiplication by 2
 Shifting to the right corresponds to division by 2
 Arithmetic shift – a shift that leaves the sign bit unchanged
 Control – instructions to direct the execution of a program
o START, STOP
o JUMP – to move to an instruction other than the next one in the list.

Parts of an instruction
Op-code – indicates which of the operations is requested
Operand – contains more detailed information about the operation specified in the op-code
Addressing mode – shows where to fetch the data to be operated on

In order to design a machine language, it is necessary to understand the machine's architecture.


Machine language is also called assembly language. In machine language, each code corresponds to an
instruction.
Program execution
A computer follows a program stored in its memory by copying the instructions from memory into the
CPU as needed. Once in the CPU, each instruction is decoded and executed. The order in which the
instructions are fetched from memory corresponds to the order in which they are stored unless altered
by the JUMP command.

There are 2 special purpose registers that control the program execution:
 Instruction register – holds the instruction currently being executed
 Program counter – contains the address of the next instruction to be executed

Machine cycle
 Fetch – CPU requests that main memory provide it with the instruction that is stored at the
address indicated by the program counter. The instruction is retrieved from main memory and
placed in the instruction register. Program counter is incremented by 2 to contain the address of
the next instruction (each instruction takes 2 memory cells).
 Decode – the instruction is now in the instruction register. It is decoded – the operand field is
broken into components based on the instruction's op-code.
 Execute – activate the appropriate circuitry to perform the requested task.

Once the instruction has been executed, the cycle for the current instruction is complete. The CPU
begins the cycle again for the next instruction.
Example of decoding an instruction:
16-bit instruction: 306E
Op-code: 3 – means: store the content of a register in a memory cell
Operand: 0 – identifies the register(R0) whose content is to be stored
6E – identifies the address of a memory cell where the data will be sent

Many programs can be stored simultaneously in main memory, as long as they occupy different
locations. As data is also kept there, the machine cannot distinguish what is data and what is a program.
This allows one program to manipulate another in the same way as it would manipulate data.

You might also like