Docsity

Computer Science: data representation and computer architecture, Sintesi del corso di Fondamenti di informatica

Toggle sidebar
bg1
Data representations
The world numbering system Western (Hindu-Arabic system) is
decimal and positional.
An electrical switch has two states: on and off (or open and
closed). The same concept stands for the binary system, based on the
digits 0 and 1.
Algorithm for finding the binary representation of a positive integer:
- Divide by 2 the original value and record the remainder;
- If the quotient is not zero, continue to divide the new
quotient by 2 and record the remainder;
- Once the quotient is equal to zero, the binary value consists of the remainder listed
from right to left in the order they were recorded.
A bit corresponds to a single digit; 8 bits form a byte. A word is an aggregation of bytes used for
memory cells.
Sum in binary: for multiple digit numbers, we perform
partial sums between bits with the same weight,
propagating the possible carriers.
Subtraction in binary: for multiple digit numbers, we
perform partial subtractions between bits with the same
weight, propagating the possible borrows.
The term overflow indicates the error that occurs, in an automatic
calculation system, when the result of an operation can’t be
represented with the same code and number of bits the operands. It’s a
dynamic condition, since it only exist because of an operation.
Issues with ranges of binary values and overflows are relevant, since all computers represent
data on a limited number of bits. Some languages “expose” these problems, others “hide” them
using internal mechanism. For example, in the C language, integers
are usually on 32 bits, the maximum positive number that can be
represented is 231 – 1. Python, instead, uses a representation of integer numbers on arbitrary
precision, there can’t be an overflow between integers.
The octal system: it has base 8, it’s useful to write binary numbers
in a compact form. Since 8 is 23, every group of 3 bits becomes an
octal digit. Digits = {0, 1, 2, 3, 4, 5, 6, 7}
The hexadecimal system: it has base 16, useful to write binary numbers in
compact form. Digits = {0, …, 9, A, B, C, D, E, F}.
A number can be positive or negative. It’s therefore easy to represent the sign in binary. The
simplest solution isn’t always the best:
- Sign and magnitude (S&M): one bit for the sign, 0 for positive and 1
for negative. N-1 for the absolute value (also called magnitude). It’s
simpler to understand, but impractical in operations.
pf3
pf4
pf5

Anteprima parziale del testo

Scarica Computer Science: data representation and computer architecture e più Sintesi del corso in PDF di Fondamenti di informatica solo su Docsity!

Data representations

The world numbering system Western (Hindu-Arabic system) is

decimal and positional.

An electrical switch has two states : on and off (or open and

closed). The same concept stands for the binary system , based on the

digits 0 and 1.

Algorithm for finding the binary representation of a positive integer:

  • Divide by 2 the original value and record the remainder;
  • If the quotient is not zero, continue to divide the new

quotient by 2 and record the remainder;

  • Once the quotient is equal to zero, the binary value consists of the remainder listed

from right to left in the order they were recorded.

A bit corresponds to a single digit; 8 bits form a byte. A word is an aggregation of bytes used for

memory cells.

Sum in binary : for multiple digit numbers, we perform

partial sums between bits with the same weight,

propagating the possible carriers.

Subtraction in binary : for multiple digit numbers, we

perform partial subtractions between bits with the same

weight, propagating the possible borrows.

The term overflow indicates the error that occurs, in an automatic

calculation system, when the result of an operation can’t be

represented with the same code and number of bits the operands. It’s a

dynamic condition , since it only exist because of an operation.

Issues with ranges of binary values and overflows are relevant , since all computers represent

data on a limited number of bits. Some languages “expose” these problems, others “hide” them

using internal mechanism. For example, in the C language, integers

are usually on 32 bits, the maximum positive number that can be

represented is 2

31

    1. Python, instead, uses a representation of integer numbers on arbitrary

precision , there can’t be an overflow between integers.

The octal system : it has base 8, it’s useful to write binary numbers

in a compact form. Since 8 is 2

3

, every group of 3 bits becomes an

octal digit. Digits = {0, 1, 2, 3, 4, 5, 6, 7}

The hexadecimal system : it has base 16, useful to write binary numbers in

compact form. Digits = {0, …, 9, A, B, C, D, E, F}.

A number can be positive or negative. It’s therefore easy to represent the sign in binary. The

simplest solution isn’t always the best:

  • Sign and magnitude ( S&M ): one bit for the sign, 0 for positive and 1

for negative. N-1 for the absolute value (also called magnitude). It’s

simpler to understand, but impractical in operations.

  • One’s complement. Given a binary number A of N bits, its one’s complement, or simple

called complement, can be defined as:

N

- 1 ) – A

Also, there’s one practical rule: the one’s complement of a binary number A can be

obtained by complementing (or inverting) all its bits.

  • Two’s complement. Given a binary number A of N bits, its two’s complement can be

defined as:

N

- A = 𝑨

It’s possible to represent negative numbers using two’s complement by:

o Considering all numbers with MSB = 0 as positives, with a value equal to their

normal binary representation (A);

o Considering all number with MSB = 1 as negatives, with a value equal to - 1

multiplied by their two’s complement (- 1 × 𝑨

Equivalently, in a two’s complement number of N bits the MSB has a negative weight

N- 1

), while the rest of the bits have a positive weight according to their position.

There are two practical rules :

o Two’s complement of a binary number A can be obtained by adding one to its

one’s complement;

o The two’s complement of a binary number is obtained starting from the LSB ,

copying all the bits up to the first “ 1 ” (included) and complementing the

remaining bits.

To convert a decimal number to 2 ’s complement, if it’s positive than the same rule as

“plain binary” is used; if it’s negative: first convert the absolute value in binary, then

compute the 1 ’s complement by inverting each bit.

Two’s complement representation is the most adopted in today’s processors, since it

simplifies the circuit implementation of the basic arithmetic operations. It’s also

possible to apply the “standard” binary arithmetic rules to all the bits composing the

number. Addition and subtraction can be done directly , without “special cases”

depending on the sign of the operands. Subtraction of A and B can also be obtained by

summing A with the two’s complement of B (A + 𝐵

If the two operands have different signs , overflow can never occur. If the two operands

have the same sign, there’s overflow when the result has opposite sign.

For representing real numbers there are two options:

  • Fixed portion : given N bits, reserve F bits for the fractional part and N – F for the integer

part. It reserves a pre-defined number of bits to integer and fractional part (fixed

precision). All the bits of the fractional part have weight 2

  • i

.

  • All circuits need to perform basic operations on integers, real numbers and logical

operations;

  • Appropriate circuits to coordinate the execution of instructions (for example their

sequencing, error checking etc.);

  • Interfacing for moving data to/from memory and I/O units.

However, it has limit capacity to store data and/or

instructions, pretty much the bare minimum necessary to

carry out the operations. For efficiency reasons a part of

memory is “ hosted ” in the microprocessor. The

microprocessor is made by three different components :

the CPU, the interfaces and the “local” memory (cache).

The CPU is made by a control unit and an operational unit

(datapath).

The operational unit performs all the required processing

(arithmetic, logical, etc.). It’s composed of:

  • ALU ( Arithmetic Logic Unit ), it performs all

calculations (arithmetic, logical, comparisons) on

integers;

  • FPU ( Floating Point Unit ), it performs calculation on real numbers (floating point).

There is a noticeable difference in execution time between ALU and FPU, the ratio

depends on the specific processor, but an FPU is usually 5 - 50 times slower than an ALU

operator;

  • Instruction and data registers , where local memory elements temporarily store data

or instructions. Each transfer between processor and memory really happens between

memory and registers. There is a limited number of registers that the CPU can handle

at the same time (usually 8-128);

  • Flag register (s), whose bits signal certain states of the set of computing units or some

information about the result of the last operation performed. They’re used to implement

some conditional instructions. Examples of important flags:

o Zero , reports whether the result of the previous operation is zero or not;

o Sign , indicates the sign of the result of the previous operation;

o Overflow , indicates whether the result of the previous operation has incurred an

overflow.

The control unit is the heart of the processor: it’s based on the

instructions contained in the program being executed and on

the state of all units , it decides the operations to be performed

and issues the related commands to the other units.

The control unit is formed of:

  • PC ( Program Counter ), it’s the register that always indicates the address of the memory

cell containing the next instruction to be executed;

  • IR ( Instruction Register ), it’s the register that stores temporarily the current instructions

to be executed;

  • Control logic , it interprets the machine code (bits) in the IR to decide and emit the

commands for the other units (ALU, FPU, etc.).

While executing an information there are three phases :

  • Fetch (get an instruction from the main memory):

IR ← M [PC] : first, it copies the instruction stored in the

main memory (M) at the address pointed by the Program

Counter (PC) into the Instruction Register (IR).

PC ← PC + 1 : then, it increments the Program Counter by

one, so its point to the next instruction in memory for the

following cycle.

  • Decode (interpret the instruction):

The control unit’s decoder reads the bit pattern in IR and translates it into specific

signal/commands that tell the hardware what operation to perform.

  • Execute (execute the instruction):

Activates the hardware functional blocks (such as ALU, registers, etc.) required to

carry out the decoded operation.

Now that the fundamental blocks of a CPU are

covered, it’s possible to evaluate which

operations are to be considered elementary →

Each processor contains a timing element, a

clock , that generates a common time

reference for all the elements that make up the processing system.

T = clock period (the second as unit)

F = clock frequency = 1/T (the Hertz as unit)

A machine cycle is the time interval in which an elementary operation is performed. It’s an

integer number of clock period. Executing an instruction requires an integer number of clock

cycles, which varies depending on the type of instruction.

The memory stores the data and instructions needed by the computer to operate. It’s

necessary for intrinsic storage and efficiency reasons. The memory has four main

characteristics :

  • Addressing. Memory is organized into cells , a cell is the smallest directly accessible

unit. Each memory cell is associated with a numeric address to uniquely identify it.

  • Parallelism. Each memory cell contains a fixed number of bits (word). It’s identical for

all the cells, accessible with a single instruction and a multiple of the byte.

  • Access (sequential or random)
  • Hierarchical structure. Ideally, memory should be as big, as cheap and as fast as

possible and retain information indefinitely. However, such a memory doesn’t exist (yet):

fast memories exist, but they are quite volatile ; all the non-volatile memories cost

relatively little but are also relatively slow.

To optimize average access time and average cost , memory is organized into levels:

o Closer to the processor, there’re the faster, more expensive memories (also

volatile, for technological reasons);

How to connect n units (CPU with memories and various

Input/Output controllers) efficiently? A single connection line is

used to connect all components, so each component is physically

hooked to this line. This line is called bus.

There are advantages and disadvantages to the bus:

  • Advantages : it reduces the cost of production, it’s extensible , making adding new

devices very easy, and it’s standardized , allowing communication on different devices.

  • Disadvantages : its slowness , since only two devices can “speak” with each other at

any time, and the processor overload , so the CPU acts like a master on the bus,

controlling its usage.

The characteristics of a bus: transporting only one piece of data at a time; the frequency is

equal to the number of data transported per second; the width is the number of bits composing

a single datum.

A single bus is divided into three sub-buses , called:

  • Data bus ( DBus ) → Transports the actual data bits. Its size indicates the size of a

memory cell;

  • Address bus ( ABus ) → Transports the address of the data to be read/written. Its size

determines the maximum number of addressable memory cells;

  • Control bus ( CBus ) → Transports additional control signals, for example, to

differentiate a read transaction from a write transaction.

The maximum internal memory ( max mem ) = 2

|Abus|

× |Dbus| bit

The external memory (for example, the disk) doesn’t depend on

Abus because it’s considered as a peripheral (input and/or

output). Its quantity depends on the I/O bus, so where peripherals

are connected.

Operating systems manage the machine’s hardware and software resources, providing basic

services to application software. Their goals are to:

  • Execute the various programs ;
  • Making the system easier to use ;
  • Using the hardware efficiency.

Typical modules and service of an operating system: process management; main memory

management; secondary memory management; I/O device management; file management

and file systems; implementation of protection mechanism; network and distributed systems

management.