Computer organisation and design - Lecture slides 2006. 1. Roger Johansson.
Embedded systems, an introduction. Roger Johansson. Associate Professor.
Roger Johansson
Embedded systems, an introduction
Roger Roger Johansson Johansson
Associate AssociateProfessor Professor
Sven Sven Knutsson Knutsson Lecturer Lecturer
Dept. Dept. of of Computer Computer Science Science and and Engineering Engineering
Computer organisation and design - Lecture slides 2006
1
Roger Johansson
Computer organisation and design
Introduction Introduction to to microcomputers microcomputers Number Number systems systems Computer Computer structures... structures... .... and and how how computers computers work work Programming Programming computers computers
Computer organisation and design - Lecture slides 2006
2
Roger Johansson
Computers now and then...
..they share the basic structures... memory
Central processing unit (CPU)
bus Inports (input) Outports (output)
Computer organisation and design - Lecture slides 2006
3
Roger Johansson
Dedicated computers General Purpose ”Mini Computer” (DE)
Altair 8800
Data aqusition system (HP) C VIC 20
Mainframe (IBM)
SOL Apple II-e Supercomputers (Cray)
IBM PCAT IBM ”portable”
Computer organisation and design - Lecture slides 2006
4
Roger Johansson
Number systems AAdecimal decimalnumber numberis iscoded codedas asaasequense sequenseof ofdigits, digits,e.g. e.g.435,72. 435,72. This is interpreted as This is interpreted as 2 44isisworth (4 worthfour fourtimes timeshundred hundred (4••10 102)) 1 33isisworth (3 worththree threetimes timesten ten (3•10 •101)) 0 55isisworth (5 worthfive fivetimes timesone one (5•10 •100)) -1 77isisworth (7 worthseven sevendivided dividedby byten ten (7••10 10-1)) -2 22isisworth (2 worthtwo twodivided dividedby byhundred hundred (2••10 10-2)) So Sothe thenumber numbercan canbe beexpressed expressedas asthe thesum sumof: of: 2 1 0 -1 -2 44••10 + 3 • 10 + 5 • 10 + 7 • 10 + 2 2 1 0 -1 10 + 3 • 10 + 5 • 10 + 7 • 10 + 2••10 10-2
Computer organisation and design - Lecture slides 2006
5
Roger Johansson
Number systems, Notation
Notation Notation for for numbers numbers with with different different number number base (radix): base (radix): (1001) radix [0,1] (1001)22 radix22 [0,1] radix 8 [0-7] (1072) radix 8 [0-7] (1072)88 radix 10 [0-9] (2934) 10 radix 10 [0-9] (2934)10 radix 16 [0-9,A-F] (3AF5) 16 radix 16 [0-9,A-F] (3AF5) 16
Prefix Prefixfor fordifferent differentradices radicesin inthe the’C’ ’C’programming programminglanguage: language: First digit is 0 (zero) denotes an octal number (radix 8) 01072 01072 First digit is 0 (zero) denotes an octal number (radix 8) 2934 A non-zero first (decimal) digit denotes a decimal number (radix10) 2934 A non-zero first (decimal) digit denotes a decimal number (radix10) 0x3AF5 prefix “0x” (zero-x) denotes a hexadecimal number (radix16) 0x3AF5The The prefix “0x” (zero-x) denotes a hexadecimal number (radix16) Prefix Prefixfor fordifferent differentradices radicesin inassembler assemblercode: code: %1001 prefix ’%’ denotes a binary number %1001The The prefix ’%’ denotes a binary number @1072 prefix ’@’ denotes an octal number @1072 The The prefix ’@’ denotes an octal number 2934 prefix denotes a decimal number 2934 No No prefix denotes a decimal number $3AF5 The prefix ’$’ denotes a hexadecimal number $3AF5 The prefix ’$’ denotes a hexadecimal number
Computer organisation and design - Lecture slides 2006
(radix 2) (radix 2) (radix 8) (radix 8) (radix 10) (radix 10) (radix16) (radix16)
6
Roger Johansson
Number systems, radix conversions, binary to decimal...
N10 = d n −1 ∗ r
n −1
+ d n−2 ∗ r
n−2
+ ..... + d 0
The Theequation equationprovides providessimple simplemethods methodsto toconvert convert numbers between different number systems, numbers between different number systems,E.g.… E.g.… Convert Convertbinary binarynumber number(101110) (101110)22to todecimal decimalform. form. Apply the equation above. The number of binary Apply the equation above. The number of binarydigits digits(n) (n)isis6, 6,so so 5 4 3 2 1 0 (N) = 1•2 + 0•2 +1•2 +1•2 +1•2 +1•2 = 5 4 3 2 1 0 (N)1010 = 1•2 + 0•2 +1•2 +1•2 +1•2 +1•2 = 32+ 0 +8 +4 +2 +0 32+ 0 +8 +4 +2 +0 ==52 52 I.e. (101110) = (52) I.e. (101110)2 = (52)10 2
10
Computer organisation and design - Lecture slides 2006
7
Roger Johansson
Number systems, radix conversions, decimal to binary ... AArewrite rewriteof ofthe theequation equationprovides providesthis thismethod... method... Convert Convertdecimal decimalnumber number211 211to toit’s it’sbinary binaryrepresentation: representation: Q/r quotient remainder Q/r quotient remainder 211/2 = 105 + 1/2 d 211/2 = 105 + 1/2 d00==11 105/2 52 ++ 1/2 dd1 ==11 105/2 == 52 1/2 1 52/2 26 ++ 00 dd2 ==00 52/2 == 26 2 26/2 = 13 + 0 d 3 26/2 = 13 + 0 d3==00 13/2 66 ++ 1/2 dd4 ==11 13/2 == 1/2 4 6/2 == 33 ++ 00 dd5 ==00 6/2 5 3/2 == 11 ++ 1/2 dd6 ==11 3/2 1/2 6 1/2 = 0 + 1/2 d 7 1/2 = 0 + 1/2 d7==11 I.e. (11010011)2 I.e.::(211) (211)10 ==(11010011) 10
Computer organisation and design - Lecture slides 2006
2
8
Roger Johansson
Number systems, radix conversions, decimal to hexadecimal ... Another Anotherrewrite rewriteof ofthe theequation equationprovides providesthis thismethod... method... Convert Convertdecimal decimalnumber number 211 211to toit’s it’shexadecimal hexadecimalrepresentation: representation: Q/r Q/r 211/16 211/16== 13/16 13/16 ==
quotient quotient (13) (13)1010==(D) (D)1616 00
remainder remainder 3/16 d 3/16 d00=3 =3 =D 13/16 d 13/16 d11=D
I.e. (D3)1616 I.e.(211) (211)1010==(D3)
Computer organisation and design - Lecture slides 2006
9
Roger Johansson
Number systems, natural binary coded decimal numbers , (NBCD code) ... AAgroup groupof offour fourbinary binarydigits digitscorresponds correspondsto toone onedecimal decimaldigit… digit…
The Thedecimal decimalnumber number9756 9756isisexpressed expressedin inNBCD-code NBCD-codeas: as: 9756 9756==1001 1001 0111 0111 0101 0101 0110 0110 99 77 55 66
Computer organisation and design - Lecture slides 2006
10
Roger Johansson
Number systems, ASCII ...
ASCII ASCII==American AmericanStandard Standard Code for Information Code for Information Interchange Interchange
Provides an interpretation of 8bit digital numbers into alphabetical and numerical characters. There are also some control characters included. Most of these are mainly of historical interest.
Computer organisation and design - Lecture slides 2006
11
Roger Johansson
Computer structures basically...
memory
Central processing unit (CPU)
bus Inports (input) Outports (output)
Computer organisation and design - Lecture slides 2006
12
Roger Johansson
Memory hierarchy primary memory
CPU registers cache memory
interface
secondary memory
block access
random access one time programmable
ROM
programmable
PROM
EPROM
• • • • •
read/write
Static
FLASH
hard discs CD/DVD Memory sticks Smartcards etc...
Dynamic
Computer organisation and design - Lecture slides 2006
13
Roger Johansson
Primary memory access data
memory
MEMORY
CPU
Central processing unit (CPU)
MEMORY
address
bus Inports (input)
control
Outports (output)
address data
Read Enable (read from memory)
1
Write Enable (write to memory)
3
control
CPU
memory
IO interface
2
4 Address bus
(input)
(output)
...
Data bus
MEMORY CPU
Computer organisation and design - Lecture slides 2006
14
Roger Johansson
Peripheral access memory
data CPU
Central processing unit (CPU)
bus
IN PORT
OUT PORT
address control
Inports (input) Outports (output)
port select address
Read Enable (read from inport)
data control
memory
CPU
Write Enable (write to outport)
IO interface
Address bus
(input)
Data bus
(output)
CPU
Computer organisation and design - Lecture slides 2006
15
Roger Johansson
The design D0 D1 D2 D3 D4 D5 D6 D7
1
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15
1 1
&
CE D0 D1 D2 D3 D4 D5 D6 D7
&
1
R/W
D0-D7
D0 D1 D2 D3 D4 D5 D6 D7
&
&
MEMORY WORD (8 bits)
CE
ADDRESS SPACE
A0-A11
(64 kByte) D0 D1 D2 D3 D4 D5 D6 D7 R/W CE
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11
D0 D1 D2 D3 D4 D5 D6 D7
CE
Computer organisation and design - Lecture slides 2006
A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11
MEMORY ADDRESS (16 bits)
16
Roger Johansson
Central Processing Unit CPU
DATA REGISTER (8 bits)
Control Unit MEMORY Instruction Register
(64 kByte)
Register File
Arithmetic Logic Unit
Program Counter PC
PROGRAM COUNTER PC (16 bits)
Width of PC determines adressable space, i.e. 16 bits Width of registers in ”Register File” determines data word size, i.e. 8 bits.
Computer organisation and design - Lecture slides 2006
17
Roger Johansson
Instruction Fetch When powered on, the CPU starts fetching and executing instructions CPU
MEMORY
Control Unit Data Instruction Register Arithmetic Logic Unit
Register File Program Program Counter PC OP-code
The Operation Code (OP-code) details the instruction...
Computer organisation and design - Lecture slides 2006
18
Roger Johansson
Instruction Execute example: Load from Memory After decoding this instruction the control unit generates the specified memory address. CPU
MEMORY
Control Unit Data Instruction Register Arithmetic Logic Unit
Register
Data
File Program Program Counter PC
Memory contents is copied to a CPU register.
Computer organisation and design - Lecture slides 2006
19
Roger Johansson
Programming computers AAcomputer computeronly onlydo dowhat whatititisisinstructed instructedto todo. do. Such Suchinstructions instructionsare areintroduced introducedby byaaprogram program
Start
Ange TV-kanal
Ange Datum
Ange Starttid
Ange Stopptid
AAdescription descriptionof ofwhat whataacomputer computer program is intended to do program is intended to doisis called calledan analgoritm. algoritm.
Visa Inställningar
Rätt Inställningar ?
NO
AAflow flowchart chartisisaadetailed detailed interpretation of an algoritm. interpretation of an algoritm.
Computer organisation and design - Lecture slides 2006
YES Stopp
20
Roger Johansson
The Water Heater Consider a water heater with inflow (cold water) and outflow which is supposed to be appropriate for a shower...
Switch IN_FLOW (ON/OFF)
LEVEL indicator (ON/OFF)
TEMPERATURE (variable)
Switch OUT_FLOW (ON/OFF)
POWER – heat conductor (variable)
Computer organisation and design - Lecture slides 2006
21
Roger Johansson
The Water Heater We apply the water heater to a computer structure and sees what we get .
COMPUTER
OBJECT IN_FLOW (ON/OFF)
CPU
OUT_FLOW ON/OFF)
POWER (VARIABLE) MEMORY LEVEL (ON/OFF)
TEMPERATURE (VARIABLE)
Interface
Computer organisation and design - Lecture slides 2006
22
Roger Johansson
The Water Heater We now want to fill up the tank with water. FILL
YES
NO LEVEL=OFF
?
OUT FLOW =OFF IN_FLOW =ON
YES
NO LEVEL=OFF
?
IN_FLOW =OFF
EXIT FILL
Computer organisation and design - Lecture slides 2006
23
Roger Johansson
CPU12 – Assembly programmers model The CPU12 programming model, has two 8-bit general-purpose accumulators (A and B) that can be concatenated into a single 16-bit accumulator (D) for certain instructions. It also has: • Two index registers (X and Y) • 16-bit stack pointer (SP) • 16-bit program counter (PC) • 8-bit condition code register (CCR)
Computer organisation and design - Lecture slides 2006
24
Roger Johansson
CPU12 – Load and Store Instructions EXAMPLE, copy byte data from memory location $600 to $400... LDAA $600 STAA $400 or.. LDAB STAB
$600 $400
Computer organisation and design - Lecture slides 2006
25
Roger Johansson
CPU12 – Addition and Subtraction Instructions EXAMPLE, subtract 10 from value at $600, store result at $400... LDAA $600 SUBA #10 STAA $400 NOTE: # means ”immediate” i.e the actual value rather than the value at location 10...
Computer organisation and design - Lecture slides 2006
26
Roger Johansson
CPU12 – Assembler programs
InPort EQU $600 InPort EQU $600 OutPort EQU $400 OutPort EQU $400 ** Line is treated as Line is treated as aa comment comment ORG $1000 ORG $1000 LDAA InPort LDAA InPort SUBA SUBA #10 #10 STAA OutPort STAA OutPort STAA OutPortCopy STAA OutPortCopy
OutPortCopy OutPortCopy
ORG ORG RMB RMB
$2000 $2000 11
substitute substitute address address with with symbol symbol code code starts starts at at this this address address
save save copy copy in in variable variable
reserve reserve space space for for variable variable
Computer organisation and design - Lecture slides 2006
27
Roger Johansson
Same program in ‘C’...
unsigned unsigned char char OutPortCopy; OutPortCopy; #define #define #define #define
InPort InPort OutPort OutPort
((char ((char *) *) 0x600) 0x600) ((char *) 0x400) ((char *) 0x400)
... ... OutPortCopy OutPortCopy == *Inport *Inport -- 10; 10; *OutPort = OutPortCopy ; *OutPort = OutPortCopy ; ... ...
Computer organisation and design - Lecture slides 2006
28
Roger Johansson
Conclusion we we have have got got aa brief brief introduction introduction to to
microcomputers microcomputers number number systems systems computer computer structures... structures... .... and and how how computers computers work work programming programming computers computers which which finishes finishes today’s today’s lecture lecture ... ...
Computer organisation and design - Lecture slides 2006
29