lecture2 en arithmetic fundamentals 2014
TRANSCRIPT
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
1/35
Arithmetic fundamentals.Numbering systems.
Converting numbers from one
number system to another
Position and non-position numbering systems.
Fundamentals of numbering systems. Decimal, binary,hexadecimal and octal numbering system. Rules forconversion of numbers from decimal to binary system.
Reverse conversion. Conversion of numbers inhexadecimal system
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
2/35
The state of modern computing
Understanding the design process, the organization ofthe computers, the technological factors and the
performance evaluation are at the core of the state of
art of modern computers
Computer architectures: Instruction set architecture
Machine organization Hardware
Technology
Interface design
Parallelism Programming
languagesApplications
Performance
measurement
and evaluation
HistoryOperating
systems
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
3/35
Computer functioning
A typical application program, widely used (like wordprocessor, email, spreadsheet, etc) consist of tens,hundreds of thousands or even more lines of code(MSOffice 2013 44 M lines of code) 1M = 18 000pages printed text
During its functioning the program also relies on othersoftware like system software, including operatingsystem (Windows 7 40 M lines code), compilers andassemblers
System software software providing commonly used
services to application programs Operating systems a program that manages and
supervises the computer resources (units) during thefunctioning of the computer
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
4/35
Computer functioning
Some of the most important functions ofthe operating system are
- handling basic I/O operations
- allocating storage and memory
- sharing the resources (processor,
memory) of the computer among multipleapplications Application softwareSystem software
Hardware
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
5/35
Computer functioning
Every computer must perform arithmeticoperations
For example in assembler (a low level
programming language, unlike C, Java, C++which are high level programming language) theinstruction:
add a, b, c
makes the computer to add 2 variables - b and and place the result in the variable
The same action in would be: = b +
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
6/35
Computer functioning
The translation of a high level language programlike C, where many actions are similar to thosein mathematics, into an assembly languageprogram is done by a program called compiler
The reason for this is that the high levellanguage programs are designed to beconvenient for use of the programmers whowrite down algorithms and present tasks in thoselanguages, while the low level languages aredesigned to be close and matching as much aspossible the hardware of the computer/processor
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
7/35
Computer functioning
Low level languages (assemblers) arebeing also translated into machinelanguage (or machine code), which can beexecuted by the processor of themachine
The machine code is loaded into the
memory of the system (computer) and theprocessor is told to start executing thiscode
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
8/35
Computer functioning
Unlike in the high level languages, the operandsfor the arithmetic instruction in the exampleabove, which can be handled by the processor
are limited by the number of registers that existin the particular processor
A register is (in general) a place, wherevariables are kept and can be accessed by the
programmers when the computer is ready forwork
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
9/35
Computer functioning
In addition to arithmetic, thecomputers/processors also execute other type ofinstructions:
Logical (logic operations AND, OR) Control (jump, branch) System (system calls for error, virtual
memory) Data transfer (moving data between registers,
memory)
Floating point On strings (comparison, concatenation) Graphical, etc.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
10/35
Computer functioning
Modern computers function on two main principles:
- the instructions are represented as numbers (eg. inMIPS architecture, the instruction add Rd=Rs+Rt ispresented as: 20 (rs) (rt) (rd) (shamt) (funct) )
- programs are stored in digital form in the memory ofthe computer and can be written and read, just likenumbers
These principles are the fundamentals of the memorystored program the memory stores the program forthe compiler, the corresponding assembly languageprogram, the text used by the compiler and thegenerated machine code
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
11/35
C program
Object: Library routine (machine language)Object: Machine language module
Executable: Machine language program
Compiler
Linker
Assembly language program
Assembler
Loader
Memory
A translation hierarchy for C. A high-level-language program is compiled
into an assembly language program and then assembled into an object
module in machine language. The linker combines multiple modules with
library routines to resolve all references. The loader then places the
machine code into the proper memory locations for execution by the
processor. To speed up the translation process, some steps are skipped or
combined together. Some compilers produce object modules directly, and
some systems use linking loaders that perform the last two steps. To
identify of file, UNIX follows a suffix convention for files: C source files
are named X.C, assembly files are X.S, object files are named X.O,
statically linked library routines are X.A, dynamically linked library
routes are X.SO, and executable files by default are called a.out. MS-
DOS uses the suffixes .C, .ASM, .OBJ, .LIB, .DLL, and .EXE to the
same effect.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
12/35
High level language program (C) swap(int v[], int k) { int temp;
temp = v[k];
v[k] = v[k+1]; v[k+1] = temp }
Assembly language program (MIPS) swap: muli $2, $5, 4 add $2, $4, $2
lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31
Binary machine language program (MIPS) 00000000101000010000000000011000
00000000000110000001100000100001 10001100011000100000000000000000 10001100111100100000000000000100 10101100111100100000000000000000 10101100011000100000000000000100 00000011111000000000000000001000
compiler
assembler
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
13/35
Computer functioning the storedprogram concept
Processor
Memory
Accounting program
(machine code)
editor (machine code)
C compiler
(machine code)
Data salaries
Text book
C program code
The stored program allowsthe computer, who runs anaccounting program to turninto a computer that runs aprogram for writing books.
The change occurs withloading the necessaryprograms and data in thememory, after which thecomputer starts the requiredprogram from a pre-defined
memory location. Theinstructions and data aretreated in the same way,which simplifies both thehardware and software.Memory technology used for
data is also used forcompilers (translating code
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
14/35
Numeral systems positional andnon-positional
For a non-positional system, the value of thedigit is not dependent on its place in the number.Such systems are the Roman, Greek, etc..
The Roman numeral system uses the digits (1000), D (500), C (100), L (50), X (10), V (5), I(1). When this symbols are given in a decreasingorder value, they are added (eg. VI = 5+1), when
a smaller digit stands before a greater one their values are substracted eg. IV = 5 - 1
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
15/35
Non-positional numeral systems
Greek numeral system, Each unit (1, 2, , 9) wasassigned a separate letter, each tens (10, 20, , 90) aseparate letter, and each hundreds (100, 200, , 900) aseparate letter. This requires 27 letters, so the 24-letterGreek alphabet was extended by using three obsolete
letters. To distinguish numerals from letters, former werefollowed by the symbol . Example: 241 is representedas (200 + 40 + 1).
TheAttic numerals were used by the ancient Greeksand resembles the Roman numeral system (the
correspondence with the Roman system is I = I, V = (), X = (), L = , C = H, D = , M = ). Unlikeit, the Attic system contains only additive forms i.e. 4 iswritten as , not as .
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
16/35
Positional numeral systems
With a positional numeral system, the value of eachdigit is given by the its posit ion in the number.
The number of different digits used in a positionalnumeral system is called the base of the system (P).
The digits are basic symbols from 0 to - 1 (the base -1). For example in decimal system = 10 and the digitsused are from 0 to 9. In the positional numeral systems,the value of each position is on as many orders biggerthan its neighbor on the right, as is the base of the
system (in decimal system 10 times). For this reason,to represent the next number after the bigger digit, a 1must be placed and moved to the left for example 9 + 1is presented as 10.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
17/35
Positional numeral systems
Digit 0 shows that there are no meaning digits in thecorresponding position. No positional number system ispossible without such digit. Hindus are the first to use 0for empty positions. At present, the most commonly used
system of numerals is the Arabic numerals.Two Indian mathematicians are credited with developingthem. Aryabhata of Kusumapura developed the place-value notation in the 5th century and a century laterBrahmagupta introduced the symbol for zero. The
numeral system and the zero concept, spread to othersurrounding countries so the Arabs adopted it andmodified them.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
18/35
Positional numeral systems
In this system, the sequence 20 822 denotes the number2.104 + 0.103 + 8.102 + 2.101 + 2.100. Having in mind thateach position on the right is 1/10 th of the value, andusing a dot to divide the digits into two groups, one canalso write fractions in the positional system. For
example, the base-2 numeral 10.11 denotes 121 +020 + 121+ 122 = 2.75. The Chinese Counting rods are small bars, typically 3
14 cm long, used by mathematicians for calculation inancient China, Japan, Korea and Vietnam. They are
placed either horizontally or vertically to represent anynumber and any fraction. Written forms based on themare called rod numerals. They are a true positionalnumeral system with digits for 1-9 and a blank for 0, fromthe Warring states period (475 BC) to the 16th century.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
19/35
Numeral systems
In general, ifp is the base, one writes a number inthe numeral system of base p as:
k
k
k
k
pn
n
n
n papapapapapaN
+++++++=
)1(
)1(
1
1
1
1
1
1 ......
The digits are natural numbers between 0 and p1,incl.
10 pai
knn aaaaaa
......1011The number is presented by the form:
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
20/35
The decimal numeral system
The decimal numeral system (also called baseten or occasionally denary, dec for short)has ten as its base. It is the numerical base mostwidely used by modern civilizations
The base 10 is the number of fingers of people the first tools for computing
The digits used are from 0 to 9, there is no digitfor 10!!!
The system is used in computing for financialoperations one can not use other systems (orfloating point presentation of big numbers), asthey are not accurate for such use
Abbreviated as (dec)
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
21/35
Binary numeral system The first known description of a binary numeral system
was given by the Indian scholar Pingala (around 5th2ndcenturies BC), binary combinations were found in China,
Africa, and other places The simplest numeral system (also called base-2
number system), represents numeric values using only
two symbols: 0 and 1. Digits: 0,1 0 = 0, 1 = 1, 2(dec) = 10, 3(dec) = 11, 4(dec) = ? 101112 = 2310
2410= ? 2 Even though it is very simple, the binary system has asignificant shortcoming the numbers have too manydigits!
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
22/35
Octal numeral system
The octal numeral system, oroct forshort, is the base-8 number system, anduses the digits 0 to 7
Number 0 = 0, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5= 5, 6 = 6, 7 = 7, 8(dec) = 10(oct), 9(dec) =11(oct), 10(dec) = 12(oct)...
2310=278 2410= ? 8 3210= ? 8
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
23/35
Hexadecimal numeral system
The hexadecimal numeral system, orhex forshort, is the base-16 number system, and usesthe digits 0 to 9, , b, c, d, e, f (or A, B, C, D, E,F)
Number 0 = 0, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6= 6, 7 = 7, 8 = 9, 9 = 9, 10(dec) = A(hex),11(dec) = B (hex), 12(dec) = C(hex), 13(dec) =D(hex), 14(dec) = E(hex), 15(dec) = F(hex),16(dec) =...
2310=1716 2410= ? 16 3210= ? 16
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
24/35
Why dont computers use decimalnumeral system ?
- ENIAC (the first electronic computer) uses 10 vacuumtubes / digit
Its implementation with electronic elements isdifficult:
1) For storage 2) To transmit - high precision is needed to code 10
levels of signal on a single wire
3) o apply digital logical functions
- addition, multiplication, etc. Digital electronics operate with only two voltage levels of
interest: a high voltage and a low voltage. All othervoltage values are temporary and occur whiletransitioning between the values
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
25/35
Digital presentation
Presentation in binary system number 1521310 is 111011011011012
number 1.2010 is 1.0011001100110011[0011]2
number 1.5213 X 104 is 1.110110111011012 X 213
Electronic presentation
Easy to implement elements with two stable states
Reliable transmission on lines with noise or low reliability
Easy to implement arithmetic functions
3.3V2.8V
0.5V0.0V
0 1 0
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
26/35
task
What are the digits that are used by abase p number system ( 2 positiveinteger), :
) 0, 1, 2, 3, , - 1, ;
b) 0, 1, 2, 3, , - 1;
c) 0, 1, 2, 3, , - 1, , + 1; d) 1, 2, 3, 4, , 1;
e) none of the above.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
27/35
task
If 2 is a positive integer every positive number can berepresented of the form:
N = anpn + an-1p
n-1 + + a1p1 + a0p
0,where ai is an integer and :
) 0 ai p-1; i = 0, , n; an 0,and this is the only representation;
b) 0 ai p; i = 0, , n; an 0,and this is the only representation;
c) 0 ai p-1; i = 0, , n; an 0,and this is not the only representation.
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
28/35
An algorithm for conversion of numbers from decimal tobinary system
The number is divided by and
get quotient and reminder. The
reminder is being recorded.
Take the quotient as a
number.
All reminders are
recorded in reverseorder. The result is the
number in base -
system
quotient = 0 yesno
End
Start
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
29/35
Example: Convert the decimal number 53 into base 2 system and base 8system.
Applying the algorithm above:
53 : 2 = 26 and reminder 1 53 : 8 = 6 and reminder 5 25 : 2 = 13 and reminder 0 6 : 8 = 0 and reminder 6 13 : 2 = 6 and reminder 1 53 = 65(8)* 6 : 2 = 3 and reminder 0 Check: 3 : 2 = 1 and reminder 1 65 (8) = 6 . 81 + 5 . 80 = 48 + 5 = 53(10)
1 : 2 = 0 and reminder 1
Check: 53 = 110101(2) = 1 . 25 + 1 . 24 + 0 . 23 + 1 . 22 + 0 . 21 + 1 . 20 = = 32 + 16 + 4 + 1 = 53
The reverse conversion from-base into decimal system is done bymultiplying the digits at each position to the power of, corresponding to theposition in the number (see the examples for the check for correctnessabove).
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
30/35
Task
Convert the decimal number 127 into base2 system
Check by the reverse conversion (frombase to into decimal)
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
31/35
Reverse conversion
binary -> decimal I approach Example : Let the number 101011 is in binary system. To convert it
in decimal, we must sum the weights of those positions, that havelogical 1. Each digit of the binary number is multiplied by the powerof 2, that corresponds to its position of the place of the 1. The one atthe most right position has the power of 0.
101011 = 1 * 25 + 0 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20 = 43 II approach Example : Let the number 101011 is in binary system. To convert it
in decimal, we must sum several numbers. Each number is 2 on thepower of n, n being the consecutive number of the digit 1 in thebinary number, the one at the most right position is 0.
101011 = 20 + 21 + 23 + 25 = 1 + 2 + 8 + 32 = 43
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
32/35
Binary-to-octal and Back
Each binary number can be converted into octal bysplitting the binary number at triads. After that, eachtriad is substituted by the corresponding octal
number/digit according to the table bellow.
Octal digit Binary number Octal digit Binary number
0
12
3
000
001010
011
4
56
7
100
101110
111
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
33/35
Binary-to-Hexadecimal and Back
Convert the following hexadecimal and binary numbers into the other base: eca86420(hex)
0001 0011 0101 0111 1001 1011 1101 1111(two)
Just a table lookup one way:
eca86420(hex)
1110 1100 1010 1000 0110 0100 0010 0000(two)
And then the other direction too:
0001 0011 0101 0111 1001 1011 1101 1111(two)
13579bdf(hex)
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
34/35
Convert
12610= ? 16 12610= ? 8
12610= ? 2 3016= ? 10 308= ? 10
10000000010= ? 2
-
8/9/2019 Lecture2 en Arithmetic Fundamentals 2014
35/35
Tasks (now)
What do you use the high level programming languagesfor?
Under which control is the coordination andsynchronization of the various components of the
computer? Name at least 3 basic hardware computer components
and 2 important software products give 1-2 examples..
Describe the work (main functions, principles) of thelinker (link editor) - 1 page (home)
Write down how many lines of code are 3 of theprograms which you are using (home)