lec01_introanalytics-for-the-internet-of-things-iot-intelligent-analytics-for-your-intelligent-devices_compress

baburaobaban 11 views 76 slides Oct 09, 2024
Slide 1
Slide 1 of 76
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76

About This Presentation

8086 Microporcessor


Slide Content

Course overview Com
p
uter Or
g
ani
z
ation and Assembl
y
Lan
g
ua
g
es
pgz ygg
Yung-Yu Chuang with slides by Kip Irvine

Logistics •Meeting time: 2:20pm-5:20pm, Monday
Classroom
: CSIE Room 103

Classroom
: CSIE Room 103
•Instructor: 莊永裕Yung-Yu Chuang
Thi itt
黃子桓
/
李根逸
/
蘇彥禎
/
張哲瀚

T
eac
hi
ng

ass
i
s
t
an
t
s:
黃子桓
/
李根逸
/
蘇彥禎
/
張哲瀚
•Webpage:
http://www.csie.ntu.edu.tw/~cyy/asm id /
p
assword
p
•Forum:
http://www.cmlab.csie.ntu.edu.tw/~cyy/forum/viewforum.php?f=21
•Mailing list: [email protected]
Please subscribe via
https://cmlmail.csie.ntu.edu.tw/mailman/listinfo/assembly/

Prerequisites • Better to have programming experience with
some high
level languages such C C ++ Java
some high
-
level languages such C
,
C ++
,
Java

• Note: it is not tested in your graduate school
entrance exam, and not listed as a required
course anymore.

Textbook • Readings and slides

References (TOY)
Princeton’s Introduction to CS, htt // i t d /i t htt
p:
//
www.cs.pr
i
nce
t
on.e
d
u
/i
n
t
ro
cs/50machine/ http://www.cs.princeton.edu/intro cs/60circuits/

References (ARM)
ARM Assembly Language Pi
Pt K d
P
rogramm
i
n
g
,
P
e
t
er
K
naggs

an
d
Stephen Welsh ARM System Developer’s Guide, Andrew Sloss, Dominic Symes and Andrew Sloss, Dominic Symes and Chris Wright

References (ARM)
Whirlwind Tour of ARM Assembly, TONC J Vij TONC
,
J
asper
Vij
n.
ARM System
-
on
-
chip Architecture

ARM System
on
chip Architecture
,

Steve Furber.

References(IA32)
Assembly Language for Intel-Based Ct
5th Editi Ki I i
C
ompu
t
ers,
5th Editi
on,
Ki
p
I
rv
i
ne

Th A t f A bl L
Rd
Th
e
A
r
t
o
f A
ssem
bl
y
L
anguage,
R
an
d
y

Hyde

References (IA32)
Michael Abrash' s Graphics Programming Bl k B k Bl
ac
k B
oo
k
Ct St A P ' C
ompu
t
er
S
ys
t
ems:
A P
rogrammer
's

Perspective, Randal E. Bryant and David R O'Hll R
.
O'H
a
ll
aron

Grading (subject to change) • Assignments (4~5 projects, 52%), most graded
by performance by performance
• Class participation (5%) • Midterm exam (18%)
•Final
p
ro
j
ect
(
25%
)
pj ( )
– Examples from previous years

Computer Organization and Assembly language • It is not only about assembly but also about

computer organization


computer organization
.

Early computers

Early programming tools

First popular PCs

Early PCs
• Intel 8086
processor processor
• 768KB memory • 20MB disk
•Dot-Matrix
printer (9-pin)

GUI/IDE

More advanced architectures
• Pipeline
SIMD

SIMD
• Multi-core •Cache

More advanced software

More “computers” around us

My computers
Desktop
(Intel Pentium D
3GHz
Nvidia
7900)
VAIO Z46TD
(I l C 2 D P9700 2 8GH )
3GHz
,

Nvidia
7900)
(I
nte
l C
ore
2 D
uo
P9700 2
.
8GH
z
)
iPhone3GS
(ARM Cortex-A8
GBA SP
833MHz)
GBA SP
(ARM7 16.78MHz)

Computer Organization and Assembly language • It is not only about assembly but also about

computer organization


computer organization
.

• It will cover
– Basic concept of computer systems and architecture
– ARM architecture and assembly language
– x86 architecture and assembly language

TOY machine

TOY machine • Starting from a simple construct

TOY machine • Build several components and connect them
together together

TOY machine • Almost as good as any computers

TOY machine
ADUP32 int A[32];10: C020
lda R1, 1
lda RA, A
20: 7101
21: 7A00
lda RC, 0
d
ld
RD 0 FF
i=0; Do {
RD tdi
22: 7C00 23 8DFF
rea
d
ld
RD
,
0
x
FF
bz RD, exit add
R2 RA RC
RD
=s
tdi
n;
if (RD==0) break;
23
:
8DFF
24: CD29 25: 12AC
add
R2
,
RA
,
RC
sti RD, R2 add RC, RC, R1
A[i]=RD;
i=i+1;
25: 12AC 26: BD02 27: 1CC1
bz R0, read
it
jl
RF i t
} while (1);
it()
28: C023 29 FF2B
ex
it
jl
RF
,

pr
i
n
t
r
hlt
pr
i
n
t
r
()
;
29
:
FF2B
2A: 0000

ARM • ARM architecture
ARM bl i

ARM
assem
bl
y

programm
i
ng

IA32 • IA-32 Processor Architecture •
Data Transfers Addressing and Arithmetic

Data Transfers
,
Addressing
,
and Arithmetic
• Procedures
• Conditional Processin
g

g
• Integer Arithmetic • Advanced Procedures • Strings and Arrays • High-Level Language Interface • Real Arithmetic (FPU) •SIMD • Code Optimization

What you will learn • Basic principle of computer architecture
H k

H
ow

your

computer

wor
k
s
• How your C programs work
• Assembly basics •
ARM assembly programming

ARM assembly programming
• IA-32 assembly programming
S ifi t FPU/MMX

S
pec
ifi
c

componen
t
s,
FPU/MMX
• Code optimization • Interface between assembly to high-level
lan
g
ua
g
e
gg

Why taking this course? • Does anyone really program in assembly
nowadays? nowadays? Yes at times you do need to write assembly

Yes
,
at times
,
you do need to write assembly
code.

It is foundation for computer architecture and

It is foundation for computer architecture and compilers. It is related to electronics, logic design and operating system design and operating system
.

CSIE courses • Hardware: electronics, digital system,
architecture architecture
• Software: operating system, compiler

wikipedia • Today, assembly language is used primarily for
direct hardware manipulation access to direct hardware manipulation
,
access to
specialized processor instructions, or to address critical performance issues Typical uses critical performance issues
.
Typical uses
aredevice drivers
, low-levelembedded systems
,
and
real
time
systems
and
real
-
time
systems
.

Reasons for not using assembly • Development time: it takes much longer to
develop in assembly Harder to debug no type develop in assembly
.
Harder to debug
,
no type
checking, side effects… M i t i bilit t t d di t t i k

M
a
i
n
t
a
i
na
bilit
y:

uns
t
ruc
t
ure
d
,
di
r
t
y
t
r
i
c
k
s
• Portability: platform-dependent

Reasons for using assembly • Educational reasons: to understand how CPUs
and compilers work Better understanding to and compilers work
.
Better understanding to
efficiency issues of various constructs. D l i il d b d th

D
eve
l
op
i
ng

comp
il
ers,
d
e
b
uggers

an
d
o
th
er

development tools.
• Hardware drivers and system code
• Embedded s
y
stems
y
• Developing libraries. •
Accessing instructions that are not available

Accessing instructions that are not available through high-level languages. Otiii f d

O
p
ti
m
i
z
i
ng
f
or

spee
d
or

space

To sum up • It is all about lack of smart compilers • Faster code, compiler is not good enough • Smaller code , compiler is not good enough, e.g.
mobile devices
,
embedded devices
,
also
,,
Smaller code →better cache performance →
faster code • Unusual architecture , there isn’t even a
compiler or compiler quality is bad eg GPU compiler or compiler quality is bad
,
eg GPU
,

DSP chips, even MMX.

Overview
• Virtual Machine Conce
p
t
p
• Data Representation •
Boolean Operations

Boolean Operations

Translating languages
English: Display the sum of A times B plus C English: Display the sum of A times B plus C
.
C++: cout << (A
*
B+C);
cout

<<

(A

B

+

C);
Intel Machine Language:
Assembly Language:
mov eax,A
Intel Machine Language: A1 00000000 F7 25 00000004
mul B
add eax,C
llWitIt
F7

25

00000004
03 05 00000008 E8 00500000
ca
ll

W
r
it
e
I
n
t
E8

00500000

Virtual machines Abstractions for computers
High-Level Language
Level 5
Assembly Language
Level 4
Operating System
Instruction Set
Level 3
A
rchitecture
Microarchitecture
Level 1
Level 2
Digital Logic
Level 0

High-level language • Level 5 • Application-oriented languages

Programs compile into assembly language Programs compile into assembly language (Level 4)
cout << (A * B + C);

Assembly language
• Level 4 • Instruction mnemonics that have a one-to-one
correspondence to machine language
• Calls functions written at the operating
s
y
stem level
(
Level 3
)
y()
• Programs are translated into machine
language (Level 2) language (Level 2)
mov eax, A mul B mul

B
add eax, C
call WriteInt

Operating system
• Level 3 • Provides services
•Pro
g
rams translated and run at the instruction
g
set architecture level (Level 2)

Instruction set architecture • Level 2 • Also known as conventional machine language
• Executed b
y
Level 1
p
ro
g
ram
ypg
(microarchitecture, Level 1)
A1 00000000
F7 25 00000004
03 05 00000008 E8 00500000

Microarchitecture • Level 1 • Interprets conventional machine instructions
(Level 2)
• Executed by digital hardware (Level 0)

Digital logic • Level 0
CPU d f di i l l i

CPU
,

constructe
d f
rom
di
g
i
ta
l l
og
i
c

gates
•System bus
•Memory

Data representation • Computer is a construction of digital circuits
with two states:
on
and
off
with two states:
on
and
off
• You need to have the ability to translate
b t diff t t ti t i b
e
t
ween
diff
eren
t
represen
t
a
ti
ons
t
o

exam
i
ne

the content of the machine
• Common number systems: binary, octal,
decimal and hexadecimal

Binary representations • Electronic Implementation
E t t ith bitbl l t

E
asy
t
o

s
t
ore

w
ith bi
s
t
a
bl
e

e
l
emen
t
s
– Reliably transmitted on noisy and inaccurate wires
0
1
0
2.8V
3.3V
0.0V 0.5V

Binary numbers • Digits are 1 and 0
( bi di it i ll d bit) (
a
bi
nary
di
g
it i
s

ca
ll
e
d
a
bit)
1 = true 0 = false
• MSB –most significant bit
• LSB –least significant bit
MSB
LSB
• Bit numbering:
1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0
MSB
LSB
A bit string could have different interpretations
0 15

A bit string could have different interpretations

Unsigned binary integers
• Each digit (bit) is either 1 or 0 • Each bit represents a power of 2:
1
1
1
1
1
1
1
1
2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
Every binary
number is a
f
sum o
f
powers
of 2

Translating binary to decimal
Weighted positional notation shows how to Weighted positional notation shows how to calculate the decimal value of each binary bit: d
(
D
2
n
1
)
(
D
2
n
2
)
(
D
2
1
)
(
D
d
ec=
(
D
n-1

2
n
-
1
)

(
D
n-2

2
n
-
2
)

...

(
D
1

2
1
)


(
D
0
2
0
)
D = binary digit binary 00001001 = decimal 9:
(1
2
3
) (1
2
0
) 9
(1

2
3
)
+
(1

2
0
)
=
9

Translating unsigned decimal to binary • Repeatedly divide the decimal integer by 2. Each
remainder is a binary digit in the translated value: remainder is a binary digit in the translated value:
37=100101 37
=

100101

Binary addition • Starting with the LSB, add each pair of digits,
include the carry if present include the carry if present
.

1
carry:
0
0
0
0
0
1
0
0
1
(4)
carry:
0
0
0
0
0
1
1
1
+
(7)
0
0
0
0
1
0
1
1
0
0
0
0
1
0
1
1
(11)
0
1
2
3
4
bit position:
5
6
7
0
1
2
3
4
bit

position:
5
6
7

Integer storage sizes
byte
16
8
Standard sizes:
16
32
word
doubleword
64
quadword
Standard sizes:
64
quadword
Practice: What is the largest unsigned integer that may be stored in 20 bits ? Practice:

What

is

the

largest

unsigned

integer

that

may

be

stored

in

20

bits?

Large measurements •Kilobyte (KB),2
10
bytes
Mb (MB)
2
20
b

M
ega
b
yte
(MB)
,

2
20
b
ytes
• Gigabyte (GB), 2
30
bytes
• Terabyte (TB), 2
40
bytes

Petabyte

Petabyte
•Exabyte
Zttbt

Z
e
tt
a
b
y
t
e
• Yottabyte

Hexadecimal integers
All values in memory are stored in binary. Because long binarynumbersarehardtoread weusehexadecimal binary

numbers

are

hard

to

read
,
we

use

hexadecimal

representation.

Translating binary to hexadecimal •Each hexadecimal digit corresponds to 4 binary
bits.

Example:Translatethebinaryinteger

Example:

Translate

the

binary

integer

000101101010011110010100 to hexadecimal:

Converting hexadecimal to decimal •Multiply each digit by its corresponding
f 16
power

o
f 16
:
dec = (D
3
16
3
) + (D
2
16
2
) + (D
1
16
1
) + (D
0
16
0
)
H 1234 l (1
16
3
)+(2
16
2
)+(3
16
1
)+(4

H
ex
1234
equa
l
s
(1

16
3
)
+
(2

16
2
)
+
(3


16
1
)
+

(4

16
0
), or decimal 4,660.

Hex3BA4equals(3

16
3
)+(11
*
16
2
)+(10

16
1
)
Hex
3BA4
equals
(3


16
)
+
(11

16
)
+
(10

16
)

+ (4 16
0
), or decimal 15,268.

Powers of 16
Used when calculating hexadecimal values up to 8 digits long:

Converting decimal to hexadecimal
decimal 422 = 1A6 hexadecimal

Hexadecimal addition Divide the sum of two digits by the number base (16) Th ti t b th l d (16)
.
Th
e

quo
ti
en
t b
ecomes
th
e

carry

va
l
ue,

an
d
the remainder is the sum digit.
36
28
28
6A1 1
36
28
28
6A
42 45 58 4B 78
6D
80
B5
78
6D
80
B5
Important skill: Programmers frequently add and subtract the addresses of variables and instructions addresses

of

variables

and

instructions
.

Hexadecimal subtraction When a borrow is required from the digit to the l ft dd 10h t th t di it' l l
e
ft
,

a
dd 10h t
o
th
e

curren
t di
g
it'
s

va
l
ue:
C6 75
1
A2 47
24 2E
Practice: The address of var1is 00400020. The address of the next variable after var1 is 0040006A How many bytes are used by var1? variable

after

var1

is

0040006A
.
How

many

bytes

are

used

by

var1?

Signed integers The highest bit indicates the sign. 1 = negative, 0 i i 0
=

pos
i
t
i
ve
sign bit sign

bit
1
1
1
1
0
1
1
0
Negative
0
0
0
0
1
0
1
0
Positive
If the highest digit of a hexadecmal integer is > 7, the value is negative Examples: 8A C5 A2 9D negative
.
Examples:

8A
,
C5
,
A2
,
9D

Two's complement notation Steps:
Complement (reverse) each bit

Complement (reverse) each bit
– Add 1
Note that 00000001 + 11111111 = 00000000

Binary subtraction • When subtracting A –B, convert B to its two's
complement complement
• Add A to (–B)
0 1 0 1 0 0 1 0 1 0

0 1 0 1 1 1 0 1 0 0
1 1 1 1 1
Advantages for 2’s complement: Advantages for 2’s complement: • No two 0’s • Sign bit
• Remove the need for separate circuits for add
and sub

Ranges of signed integers The highest bit is reserved for the sign. This limits therange: the

range:

Character • Character sets
St d d ASCII
(0
127)

St
an
d
ar
d ASCII
(0

127)
– Extended ASCII (0 –255)
ANSI (0
255)

ANSI (0

255)
–Unicode (0 –65,535)
• Null-terminated String
– Array of characters followed by a null byte
• Using the ASCII table
– back inside cover of book

Representing Instructions int sum(int x, int y) {
PC
s
um
A
l
p
ha sumSun
s
um
{
return x+y;
}
55 89
00 00
p
81 C3
– For this example, Alpha &
Sun use two 4-byte
E
5
8B 45
3
0
42 01
E
0
08 90
instructions
• Use differing numbers of
instructions in other cases
0C 03 4
5
80 FA 6
B
02 00 0
9
instructions in other cases
– PC uses 7 instructions
with len
g
ths 1
,
2
,
and 3
08 89 EC
Diff t hi t t ll diff t
g,,
bytes
• Same for NT and for Linux
EC 5D C3
Diff
eren
t
mac
hi
nes use
t
o
t
a
ll
y
diff
eren
t

instructions and encodings
• NT / Linux not fully binary
compatible

Boolean algebra • Boolean expressions created from:
– NOT, AND, OR

NOT
• Inverts (reverses) a boolean value • Truth table for Boolean NOT operator:
Digital gate diagram for NOT:
N
OT
NOT

AND
• Truth if both are true • Truth table for Boolean AND operator:
Digital gate diagram for AND:
AND

OR
• True if either is true • Truth table for Boolean OR operator:
Digital gate diagram for OR:
OR

Operator precedence
• NOT > AND > OR • Examples showing the order of operations: •
Use parentheses to avoid ambiguity Use parentheses to avoid ambiguity

Implementation of gates • Fluid switch
(http://www.cs.princeton.edu/introcs/lectures/fluid-computer.swf
)

Implementation of gates

Implementation of gates

Truth Tables
(1 of 2)
• A Boolean function has one or more Boolean
i d il Bl i
nputs,

an
d
returns

a

s
i
ng
l
e
B
oo
l
ean

output.
• A truth table shows all the inputs and outputs
of a Boolean function Example: X Y

Truth Tables
(2 of 2)
• Example: X Y