Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The...
-
Upload
priyanka-meena -
Category
Documents
-
view
225 -
download
3
Transcript of Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The...
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
1/93
COMPUTER ORGANIZATION AND DThe Hardware/Software Interface
5thEdition
Chap er 2
Instructions: Languageof the Computer
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
2/93
Chapter 2 — Instructions: Language of the Computer — 2
Instruction Set
The repertoire of instructions of acomputer Different computers have different
instruction sets But with many aspects in common
Early computers had very simpleinstruction sets Simplified implementation
Many modern computers also have simpleinstruction sets
§2!Introductio n
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
3/93
Chapter 2 — Instructions: Language of the Computer — 3
The MIPS Instruction Set
"sed as the e#ample throu$hout the %oo& Stanford MI'S commerciali(ed %y MI'S
Technolo$ies )wwwmipscom* +ar$e share of em%edded core mar&et
,pplications in consumer electronics- networ&/stora$ee.uipment- cameras- printers-
Typical of many modern IS,s
See MI'S 0eference Data tear1out card- and ,ppendi#es B and E
http://www.mips.com/http://www.mips.com/
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
4/93
Chapter 2 — Instructions: Language of the Computer — 4
Arithmetic Operations
,dd and su%tract- three operands Two sources and one destination
add a, b, c # a gets b + c
,ll arithmetic operations have this form Design Principle 1: Simplicity favours
re$ularity
0e$ularity ma&es implementation simpler Simplicity ena%les hi$her performance at
lower cost
§22peratio
n softhe3omp
uterHa
rdware
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
5/93
Chapter 2 — Instructions: Language of the Computer — 5
Arithmetic !amp"e
3 code4f = (g + h) - (i + j);
3ompiled MI'S code4
add t0, g, h # temp t0 = g + hadd t1, i, j # temp t1 = i + jsub f, t0, t1 # f = t0 - t1
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
6/93
Chapter 2 — Instructions: Language of the Computer — #
$egister Operan%s
,rithmetic instructions use re$ister operands
MI'S has a 52 6 521%it re$ister file "se for fre.uently accessed data
7um%ered 8 to 5! 521%it data called a 9word:
,ssem%ler names ;t8- ;t!- - ;t< for temporary values
;s8- ;s!- - ;s= for saved varia%les Design Principle 2: Smaller is faster
cf main memory4 millions of locations
§25perand
s ofthe3ompu
terHar d
ware
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
7/93Chapter 2 — Instructions: Language of the Computer — &
$egister Operan% !amp"e
3 code4f = (g + h) - (i + j); f- - > in ;s8- - ;s?
3ompiled MI'S code4add $t0, $s1, $s2add $t1, $s3, $s4sub $s0, $t0, $t1
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
8/93Chapter 2 — Instructions: Language of the Computer — '
Memor( Operan%s
Main memory used for composite data ,rrays- structures- dynamic data
To apply arithmetic operations +oad values from memory into re$isters Store result from re$ister to memory
Memory is %yte addressed Each address identifies an @1%it %yte
Aords are ali$ned in memory ,ddress must %e a multiple of ?
MI'S is Bi$ Endian Most1si$nificant %yte at least address of a word c.f. +ittle Endian4 least1si$nificant %yte at least address
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
9/93
Chapter 2 — Instructions: Language of the Computer — )
Memor( Operan% !amp"e *
3 code4g = h + A!"; $ in ;s!- h in ;s2- %ase address of , in ;s5
3ompiled MI'S code4 Inde# @ re.uires offset of 52
? %ytes per word
$t0, 32($s3) # %ad %&dadd $s1, $s2, $t0
offset %ase re$ister
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
10/93
Chapter 2 — Instructions: Language of the Computer — *+
Memor( Operan% !amp"e 2
3 code4A12" = h + A!"; h in ;s2- %ase address of , in ;s5
3ompiled MI'S code4 Inde# @ re.uires offset of 52
$t0, 32($s3) # %ad %&dadd $t0, $s2, $t0s $t0, 4!($s3) # st%&e %&d
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
11/93
Chapter 2 — Instructions: Language of the Computer — **
$egisters ,s- Memor(
0e$isters are faster to access thanmemory peratin$ on memory data re.uires loads
and stores More instructions to %e e#ecuted
3ompiler must use re$isters for varia%lesas much as possi%le nly spill to memory for less fre.uently used
varia%les 0e$ister optimi(ation is important
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
12/93
Chapter 2 — Instructions: Language of the Computer — *2
Imme%iate Operan%s
3onstant data specified in an instructionaddi $s3, $s3, 4 7o su%tract immediate instruction
Cust use a ne$ative constantaddi $s2, $s1, -1
Design Principle 3: Ma&e the commoncase fast Small constants are common Immediate operand avoids a load instruction
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
13/93
Chapter 2 — Instructions: Language of the Computer — *3
The Constant .ero
MI'S re$ister 8 );(ero* is the constant 8 3annot %e overwritten
"seful for common operations
E$- move %etween re$istersadd $t2, $s1, $'e&%
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
14/93
Chapter 2 — Instructions: Language of the Computer — *4
/nsigne% 0inar( Integers
iven an n1%it num%er 8
8!
!2n
2n!n
!n 2#2#2#2## ++++= −
−
−
−
0an$e4 8 to 2n F ! E#ample
8888 8888 8888 8888 8888 8888 8888 !8!!2G 8 !625 8622 !62! !628
G 8 @ 8 2 ! G !!!8
"sin$ 52 %its 8 to ?-2
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
15/93
Chapter 2 — Instructions: Language of the Computer — *5
2s1Comp"ement Signe% Integers
iven an n1%it num%er 8
8!
!2n
2n!n
!n 2#2#2#2## ++++−= −
−
−
−
0an$e4 F2n F ! to 2n F ! F ! E#ample
!!!! !!!! !!!! !!!! !!!! !!!! !!!! !!882G F!625! !6258 !622 862! 8628
G F2-!?=-?@5-?@ 2-!?=-?@5-?? G F?!8
"sin$ 52 %its F2-!?=-?@5-?@ to 2-!?=-?@5-?=
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
16/93
Chapter 2 — Instructions: Language of the Computer — *#
2s1Comp"ement Signe% Integers
Bit 5! is si$n %it ! for ne$ative num%ers 8 for non1ne$ative num%ers
F)F2n F !* canJt %e represented
7on1ne$ative num%ers have the same unsi$nedand 2s1complement representation Some specific num%ers
84 8888 8888 8888
F!4 !!!! !!!! !!!! Most1ne$ative4 !888 8888 8888 Most1positive4 8!!! !!!! !!!!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
17/93
Chapter 2 — Instructions: Language of the Computer — *&
Signe% egation
3omplement and add ! 3omplement means ! K 8- 8 K !
#!#
!!!!!!!!## 2
−=+
−==+
E#ample4 ne$ate 2
2 G 8888 8888 88!82 F2 G !!!! !!!! !!8!2 !
G !!!! !!!! !!!82
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
18/93 §
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
19/93
Chapter 2 — Instructions: Language of the Computer — *)
$epresenting Instructions
Instructions are encoded in %inary 3alled machine code
MI'S instructions Encoded as 521%it instruction words
Small num%er of formats encodin$ operation code)opcode*- re$ister num%ers-
0e$ularity
0e$ister num%ers ;t8 F ;t= are re$Js @ F ! ;t@ F ;t< are re$Js 2? F 2 ;s8 F ;s= are re$Js ! F 25
§20epresen
tin$Instruction
sinthe
3omputer
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
20/93
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
21/93
Chapter 2 — Instructions: Language of the Computer — 2*
$1format !amp"e
add $t0, $s1, $s2
special ;s! ;s2 ;t8 8 add
8 != !@ @ 8 52
888888 !888! !88!8 8!888 88888 !88888
888888!888!!88!88!88888888!888882 G 8252?828!
op rs rt rd shamt funct %its %its %its %its %its %its
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
22/93
Chapter 2 — Instructions: Language of the Computer — 22
e!a%ecima"
Base ! 3ompact representation of %it strin$s ? %its per he# di$it
8 8888 ? 8!88 @ !888 c !!88
! 888! 8!8! < !88! d !!8!
2 88!8 8!!8 a !8!8 e !!!8
5 88!! = 8!!! % !8!! f !!!!
E#ample4 eca@ ?28 !!!8 !!88 !8!8 !888 8!!8 8!88 88!8 8888
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
23/93
Chapter 2 — Instructions: Language of the Computer — 23
MIPS I1format Instructions
Immediate arithmetic and load/store instructions rt4 destination or source re$ister num%er 3onstant4 F2!I to 2!I F ! ,ddress4 offset added to %ase address in rs
Design Principle 4: ood desi$n demands $ood
compromises Different formats complicate decodin$- %ut allow 521%itinstructions uniformly
eep formats as similar as possi%le
op rs rt constant or address %its %its %its ! %its
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
24/93
Chapter 2 — Instructions: Language of the Computer — 24
Store% Program Computers
Instructions represented in%inary- >ust li&e data
Instructions and data storedin memory
'ro$rams can operate onpro$rams e$- compilers- lin&ers-
Binary compati%ility allows
compiled pro$rams to wor&on different computers Standardi(ed IS,s
The BIG Pic ure
§
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
25/93
Chapter 2 — Instructions: Language of the Computer — 25
Logica" Operations
Instructions for %itwise manipulationperation 3 Cava MI'S
Shift left NN NN s
Shift ri$ht LL LLLs&
Bitwise ,7D O O ad, adi
Bitwise 0 P P %&, %&i
Bitwise 7T Q Q %&
"seful for e#tractin$ and insertin$$roups of %its in a word
§2+o$ical
perations
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
26/93
Chapter 2 — Instructions: Language of the Computer — 2#
Shift Operations
shamt4 how many positions to shift
Shift left lo$ical Shift left and fill with 8 %its s %y i %its multiplies %y 2i
Shift ri$ht lo$ical Shift ri$ht and fill with 8 %its s& %y i %its divides %y 2i )unsi$ned only*
op rs rt rd shamt funct
%its %its %its %its %its %its
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
27/93
Chapter 2 — Instructions: Language of the Computer — 2&
A Operations
"seful to mas& %its in a word Select some %its- clear others to 8
ad $t0, $t1, $t2
8888 8888 8888 8888 8888 !!8! !!88 8888
8888 8888 8888 8888 88!! !!88 8888 8888
;t2
;t!
8888 8888 8888 8888 8888 !!88 8888 8888;t8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
28/93
Chapter 2 — Instructions: Language of the Computer — 2'
O$ Operations
"seful to include %its in a word Set some %its to !- leave others unchan$ed
%& $t0, $t1, $t2
8888 8888 8888 8888 8888 !!8! !!88 8888
8888 8888 8888 8888 88!! !!88 8888 8888
;t2
;t!
8888 8888 8888 8888 88!! !!8! !!88 8888;t8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
29/93
Chapter 2 — Instructions: Language of the Computer — 2)
OT Operations
"seful to invert %its in a word 3han$e 8 to !- and ! to 8 MI'S has 70 51operand instruction
a 70 % GG 7T ) a 0 % *%& $t0, $t1, $'e&%
8888 8888 8888 8888 88!! !!88 8888 8888;t!
!!!! !!!! !!!! !!!! !!88 88!! !!!! !!!!;t8
0e$ister 84 alwaysread as (ero
§2
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
30/93
Chapter 2 — Instructions: Language of the Computer — 3+
Con%itiona" Operations
Branch to a la%eled instruction if acondition is true therwise- continue se.uentially
be &s, &t, *1 if )rs GG rt* %ranch to instruction la%eled +!R
be &s, &t, *1 if )rs G rt* %ranch to instruction la%eled +!R
j *1 unconditional >ump to instruction la%eled +!
2=Instructio
n sforMa&in$D
ecision
s
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
31/93
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
32/93
Chapter 2 — Instructions: Language of the Computer — 32
Compi"ing Loop Statements
3 code4
hie (sa/ei" == ) i += 1;
i in ;s5- & in ;s- address of save in ;s
3ompiled MI'S code4*%%p s $t1, $s3, 2 add $t1, $t1, $s $t0, 0($t1)
be $t0, $s, it addi $s3, $s3, 1 j *%%pit .
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
33/93
Chapter 2 — Instructions: Language of the Computer — 33
0asic 0"ocs
, %asic %loc& is a se.uence of instructionswith 7o em%edded %ranches )e#cept at end* 7o %ranch tar$ets )e#cept at %e$innin$*
, compiler identifies %asic%loc&s for optimi(ation
,n advanced processorcan accelerate e#ecutionof %asic %loc&s
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
34/93
Chapter 2 — Instructions: Language of the Computer — 34
More Con%itiona" Operations
Set result to ! if a condition is true therwise- set to 8
st &d, &s, &t
if )rs N rt* rd G !R else rd G 8R sti &t, &s, c%stat
if )rs N constant* rt G !R else rt G 8R
"se in com%ination with be- best $t0, $s1, $s2 # if ($s1 $s2)be $t0, $'e&%, * # b&ach t% *
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
35/93
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
36/93
Chapter 2 — Instructions: Language of the Computer — 3#
Signe% ,s- /nsigne%
Si$ned comparison4st
-sti
"nsi$ned comparison4 stu- stui E#ample
;s8 G !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! ;s! G 8888 8888 8888 8888 8888 8888 8888 888! st $t0, $s0, $s1 # siged
F! N ! ⇒ ;t8 G !
stu $t0, $s0, $s1 # usiged ?-2
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
37/93
Chapter 2 — Instructions: Language of the Computer — 3&
Proce%ure Ca""ing
Steps re.uired
! 'lace parameters in re$isters
2 Transfer control to procedure
5 ,c.uire stora$e for procedure
? 'erform procedureJs operations
'lace result in re$ister for caller
0eturn to place of call
2@Supportin
$'roceduresi n
3omp
uterHard
ware
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
38/93
Chapter 2 — Instructions: Language of the Computer — 3'
$egister /sage
;a8 F ;a54 ar$uments )re$Js ? F =* ;v8- ;v!4 result values )re$Js 2 and 5* ;t8 F ;t
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
39/93
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
40/93
Chapter 2 — Instructions: Language of the Computer — 4+
Leaf Proce%ure !amp"e
3 code4
it eaf5eampe (it g, h, i, j)6 it f; f = (g + h) - (i + j);
&etu& f;7 ,r$uments $- - > in ;a8- - ;a5
f in ;s8 )hence- need to save ;s8 on stac&* 0esult in ;v8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
41/93
Chapter 2 — Instructions: Language of the Computer — 4*
Leaf Proce%ure !amp"e
MI'S code4eaf5eampe addi $sp, $sp, -4 s $s0, 0($sp)
add $t0, $a0, $a1 add $t1, $a2, $a3 sub $s0, $t0, $t1 add $/0, $s0, $'e&% $s0, 0($sp) addi $sp, $sp, 4 j& $&a
Save $s0 on stack
Procedure body
Restore $s0
Result
Return
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
42/93
Chapter 2 — Instructions: Language of the Computer — 42
on1Leaf Proce%ures
'rocedures that call other procedures
Vor nested call- caller needs to save onthe stac&4 Its return address ,ny ar$uments and temporaries needed after
the call
0estore from the stac& after the call
f
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
43/93
Chapter 2 — Instructions: Language of the Computer — 43
on1Leaf Proce%ure !amp"e
3 code4
it fact (it )6if ( 1) &etu& f;
ese &etu& 8 fact( - 1);7 ,r$ument n in ;a8
0esult in ;v8
L f P % "
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
44/93
Chapter 2 — Instructions: Language of the Computer — 44
on1Leaf Proce%ure !amp"e
MI'S code4fact addi $sp, $sp, -! # adjust stac f%& 2 items s $&a, 4($sp) # sa/e &etu& add&ess s $a0, 0($sp) # sa/e a&gumet sti $t0, $a0, 1 # test f%& 1
be $t0, $'e&%, *1 addi $/0, $'e&%, 1 # if s%, &esut is 1 addi $sp, $sp, ! # p%p 2 items f&%m stac j& $&a # ad &etu&*1 addi $a0, $a0, -1 # ese dec&emet
ja fact # &ecu&si/e ca
$a0, 0($sp) # &est%&e %&igia $&a, 4($sp) # ad &etu& add&ess addi $sp, $sp, ! # p%p 2 items f&%m stac mu $/0, $a0, $/0 # mutip9 t% get &esut j& $&a # ad &etu&
L " t th St
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
45/93
Chapter 2 — Instructions: Language of the Computer — 45
Loca" ata on the Stac
+ocal data allocated %y callee e$- 3 automatic varia%les
'rocedure frame )activation record* "sed %y some compilers to mana$e stac& stora$e
M L t
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
46/93
Chapter 2 — Instructions: Language of the Computer — 4#
Memor( La(out
Te#t4 pro$ram code Static data4 $lo%al
varia%les e$- static varia%les in 3-
constant arrays and strin$s ;$p initiali(ed to address
allowin$ Woffsets into thisse$ment
Dynamic data4 heap E$- malloc in 3- new in
Cava
Stac&4 automatic stora$e
Ch t t
§2
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
47/93
Chapter 2 — Instructions: Language of the Computer — 4&
Character ata
Byte1encoded character sets ,S3II4 !2@ characters
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
48/93
Chapter 2 — Instructions: Language of the Computer — 4'
0(te6a"f7or% Operations
3ould use %itwise operations
MI'S %yte/halfword load/store Strin$ processin$ is a common case
b &t, %ffset(&s) h &t, %ffset(&s)
Si$n e#tend to 52 %its in rt
bu &t, %ffset(&s) hu &t, %ffset(&s)
Xero e#tend to 52 %its in rt
sb &t, %ffset(&s) sh &t, %ffset(&s)
Store >ust ri$htmost %yte/halfword
St i C "
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
49/93
Chapter 2 — Instructions: Language of the Computer — 4)
String Cop( !amp"e
3 code )naYve*4 7ull1terminated strin$
/%id st&cp9 (cha& ", cha& 9")6 it i;
i = 0; hie ((i"=9i"):=
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
50/93
Chapter 2 — Instructions: Language of the Computer — 5+
String Cop( !amp"e
MI'S code4st&cp9 addi $sp, $sp, -4 # adjust stac f%& 1 item s $s0, 0($sp) # sa/e $s0 add $s0, $'e&%, $'e&% # i = 0*1 add $t1, $s0, $a1 # add& %f 9i" i $t1
bu $t2, 0($t1) # $t2 = 9i" add $t3, $s0, $a0 # add& %f i" i $t3 sb $t2, 0($t3) # i" = 9i" be $t2, $'e&%, *2 # eit %%p if 9i" == 0
addi $s0, $s0, 1 # i = i + 1 j *1 # et ite&ati% %f %%p
*2 $s0, 0($sp) # &est%&e sa/ed $s0 addi $sp, $sp, 4 # p%p 1 item f&%m stac j& $&a # ad &etu&
32 8it C t t§2
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
51/93
Chapter 2 — Instructions: Language of the Computer — 5*
8888 8888 8!!! !!8! 8888 8888 8888 8888
3218it Constants
Most constants are small !1%it immediate is sufficient
Vor the occasional 521%it constant
ui &t, c%stat 3opies !1%it constant to left ! %its of rt 3lears ri$ht ! %its of rt to 8
hi $s0, 1
8888 8888 8!!! !!8! 8888 !88! 8888 8888%&i $s0, $s0, 2304
!8MI'S,d
dressin$for52
1BitIm
mediates
and
,ddres
ses
0 h A%% i
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
52/93
Chapter 2 — Instructions: Language of the Computer — 52
0ranch A%%ressing
Branch instructions specify pcode- two re$isters- tar$et address
Most %ranch tar$ets are near %ranch Vorward or %ac&ward
op rs rt constant or address
%its %its %its ! %its
'31relative addressin$ Tar$et address G '3 offset 6 ? '3 already incremented %y ? %y this time
9 A%% i
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
53/93
Chapter 2 — Instructions: Language of the Computer — 53
9ump A%%ressing
Cump )j and ja* tar$ets could %eanywhere in te#t se$ment Encode full address in instruction
op address
%its 2 %its
)'seudo*Direct >ump addressin$
Tar$et address G '35!2@ 4 )address 6 ?*
T t A%% i "
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
54/93
Chapter 2 — Instructions: Language of the Computer — 54
Target A%%ressing !amp"e
+oop code from earlier e#ample ,ssume +oop at location @8888
*%%p s $t1, $s3, 2 @8888 8 8 !< < ? 8
add $t1, $t1, $s @888? 8 < 22 < 8 52
$t0, 0($t1) @888@ 5 < @ 8
be $t0, $s, it @88!2 @ 2! 2
addi $s3, $s3, 1 @88! @ !< !< !
j *%%p @8828 2 28888
it . @882?
0 hi A
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
55/93
Chapter 2 — Instructions: Language of the Computer — 55
0ranching ar A7a(
If %ranch tar$et is too far to encode with!1%it offset- assem%ler rewrites the code
E#ample
be $s0,$s1, *1
Z
be $s0,$s1, *2j *1
*2 .
A%%ressing Mo%e Summar(
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
56/93
Chapter 2 — Instructions: Language of the Computer — 5#
A%%ressing Mo%e Summar(
S(nchroni;ation§2!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
57/93
Chapter 2 — Instructions: Language of the Computer — 5&
S(nchroni;ation
Two processors sharin$ an area of memory '! writes- then '2 reads Data race if '! and '2 donJt synchroni(e
0esult depends of order of accesses
Hardware support re.uired ,tomic read/write memory operation 7o other access to the location allowed %etween the
read and write
3ould %e a sin$le instruction E$- atomic swap of re$ister [ memory r an atomic pair of instructions
!!'arallelis
mandInstruc
tions4S
ynchroni(ation
S(nchroni;ation in MIPS
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
58/93
Chapter 2 — Instructions: Language of the Computer — 5'
S(nchroni;ation in MIPS
+oad lin&ed4 &t, %ffset(&s) Store conditional4 sc &t, %ffset(&s)
Succeeds if location not chan$ed since the 0eturns ! in rt
Vails if location is chan$ed 0eturns 8 in rt
E#ample4 atomic swap )to test/set loc& varia%le*t&9 add $t0,$'e&%,$s4 ;c%p9 echage /aue
$t1,0($s1) ;%ad ied
sc $t0,0($s1) ;st%&e c%diti%a be $t0,$'e&%,t&9 ;b&ach st%&e fais
add $s4,$'e&%,$t1 ;put %ad /aue i $s4
Trans"ation an% Startup§2!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
59/93
Chapter 2 — Instructions: Language of the Computer — 5)
Trans"ation an% Startup
Many compilers produceo%>ect modules directly
Static lin&in$
!2Translati
n$andStartin
$
a'ro
$ram
Assem8"er Pse %oinstr ctions
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
60/93
Chapter 2 — Instructions: Language of the Computer — #+
Assem8"er Pseu%oinstructions
Most assem%ler instructions representmachine instructions one1to1one
'seudoinstructions4 fi$ments of theassem%lerJs ima$ination
m%/e $t0, $t1 K add $t0, $'e&%, $t1
bt $t0, $t1, * K st $at, $t0, $t1be $at, $'e&%, *
;at )re$ister !*4 assem%ler temporary
Pro%ucing an O8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
61/93
Chapter 2 — Instructions: Language of the Computer — #*
Pro%ucing an O8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
62/93
Chapter 2 — Instructions: Language of the Computer — #2
Lining O8
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
63/93
Chapter 2 — Instructions: Language of the Computer — #3
Loa%ing a Program
+oad from ima$e file on dis& into memory
! 0ead header to determine se$ment si(es
2 3reate virtual address space
5 3opy te#t and initiali(ed data into memory r set pa$e ta%le entries so they can %e faulted in
? Set up ar$uments on stac&
Initiali(e re$isters )includin$ ;sp- ;fp- ;$p*
Cump to startup routine 3opies ar$uments to ;a8- and calls main Ahen main returns- do e#it syscall
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
64/93
La;( Linage
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
65/93
Chapter 2 — Instructions: Language of the Computer — #5
La;( Linage
Indirection ta%le
Stu%4 +oads routine ID-Cump to lin&er/loader
+in&er/loader code
Dynamicallymapped code
Starting 9a,a App"ications
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
66/93
Chapter 2 — Instructions: Language of the Computer — ##
Starting 9a,a App"ications
Simple porta%leinstruction set for
the C\M
Interprets%ytecodes
3ompiles%ytecodes of9hot: methods
into nativecode for host
machine
C Sort !amp"e§2!5
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
67/93
Chapter 2 — Instructions: Language of the Computer — #&
C Sort !amp"e
Illustrates use of assem%ly instructionsfor a 3 %u%%le sort function
Swap procedure )leaf*/%id sap(it /", it )
6 it temp; temp = /"; /" = /+1";
/+1" = temp;7 v in ;a8- & in ;a!- temp in ;t8
5,3
Sort
E#ampleto'u
t
It,ll
To$ether
The Proce%ure S7ap
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
68/93
Chapter 2 — Instructions: Language of the Computer — #'
The Proce%ure S7ap
sap s $t1, $a1, 2 # $t1 = 8 4
add $t1, $a0, $t1 # $t1 = /+(84) # (add&ess %f /")
$t0, 0($t1) # $t0 (temp) = /"
$t2, 4($t1) # $t2 = /+1"
s $t2, 0($t1) # /" = $t2 (/+1")
s $t0, 4($t1) # /+1" = $t0 (temp)
j& $&a # &etu& t% caig &%utie
The Sort Proce%ure in C
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
69/93
Chapter 2 — Instructions: Language of the Computer — #)
The Sort Proce%ure in C
7on1leaf )calls swap*
/%id s%&t (it /", it )6 it i, j; f%& (i = 0; i ; i += 1) 6
f%& (j = i 1; j >= 0 ?? /j" > /j + 1"; j -= 1) 6 sap(/,j); 7 77
v in ;a8- & in ;a!- i in ;s8- > in ;s!
The Proce%ure 0o%(
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
70/93
Chapter 2 — Instructions: Language of the Computer — &+
The Proce%ure 0o%( m%/e $s2, $a0 # sa/e $a0 it% $s2
m%/e $s3, $a1 # sa/e $a1 it% $s3
m%/e $s0, $'e&% # i = 0f%&1tst st $t0, $s0, $s3 # $t0 = 0 if $s0 @ $s3 (i @ )
be $t0, $'e&%, eit1 # g% t% eit1 if $s0 @ $s3 (i @ )
addi $s1, $s0, 1 # j = i 1
f%&2tst sti $t0, $s1, 0 # $t0 = 1 if $s1 0 (j 0)
be $t0, $'e&%, eit2 # g% t% eit2 if $s1 0 (j 0)
s $t1, $s1, 2 # $t1 = j 8 4
add $t2, $s2, $t1 # $t2 = / + (j 8 4)
$t3, 0($t2) # $t3 = /j"
$t4, 4($t2) # $t4 = /j + 1"
st $t0, $t4, $t3 # $t0 = 0 if $t4 @ $t3
be $t0, $'e&%, eit2 # g% t% eit2 if $t4 @ $t3
m%/e $a0, $s2 # 1st pa&am %f sap is / (%d $a0)
m%/e $a1, $s1 # 2d pa&am %f sap is j
ja sap # ca sap p&%cedu&e
addi $s1, $s1, 1 # j = 1
j f%&2tst # jump t% test %f ie& %%p
eit2 addi $s0, $s0, 1 # i += 1
j f%&1tst # jump t% test %f %ute& %%p
'ass
paramsO call
Moveparams
Inner loop
uter loop
Inner loop
uter loop
The u"" Proce%ure
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
71/93
Chapter 2 — Instructions: Language of the Computer — &*
s%&t addi $sp,$sp, 20 # mae &%%m % stac f%& &egiste&s
s $&a, 1($sp) # sa/e $&a % stac
s $s3,12($sp) # sa/e $s3 % stac
s $s2, !($sp) # sa/e $s2 % stac
s $s1, 4($sp) # sa/e $s1 % stac
s $s0, 0($sp) # sa/e $s0 % stac
. # p&%cedu&e b%d9
.
eit1 $s0, 0($sp) # &est%&e $s0 f&%m stac $s1, 4($sp) # &est%&e $s1 f&%m stac
$s2, !($sp) # &est%&e $s2 f&%m stac
$s3,12($sp) # &est%&e $s3 f&%m stac
$&a,1($sp) # &est%&e $&a f&%m stac
addi $sp,$sp, 20 # &est%&e stac p%ite&
j& $&a # &etu& t% caig &%utie
The u"" Proce%ure
ffect of Compi"er Optimi;ation
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
72/93
Chapter 2 — Instructions: Language of the Computer — &2
ffect of Compi"er Optimi;ation
Compiled with gcc for Pentium 4 under Linu
ffect of Language an% A"gorithm
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
73/93
Chapter 2 — Instructions: Language of the Computer — &3
ffect of Language an% A"gorithm
Lessons Learnt
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
74/93
Chapter 2 — Instructions: Language of the Computer — &4
Lessons Learnt
Instruction count and 3'I are not $oodperformance indicators in isolation
3ompiler optimi(ations are sensitive to theal$orithm
Cava/CIT compiled code is si$nificantlyfaster than C\M interpreted 3ompara%le to optimi(ed 3 in some cases
7othin$ can fi# a dum% al$orithm
Arra(s ,s Pointers§2!?
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
75/93
Chapter 2 — Instructions: Language of the Computer — &5
Arra(s ,s- Pointers
,rray inde#in$ involves Multiplyin$ inde# %y element si(e ,ddin$ to array %ase address
'ointers correspond directly to memoryaddresses 3an avoid inde#in$ comple#ity
?,rraysv
ersus'ointers
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
76/93
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
77/93
A$M = MIPS Simi"arities§2!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
78/93
Chapter 2 — Instructions: Language of the Computer — &'
A$M = MIPS Simi"arities
,0M4 the most popular em%edded core Similar %asic set of instructions to MI'S
0ealStu
ff4,0M
Instruc
tions
,0M MI'S
Date announced !
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
79/93
Chapter 2 — Instructions: Language of the Computer — &)
Compare an% 0ranch in A$M
"ses condition codes for result of anarithmetic/lo$ical instruction 7e$ative- (ero- carry- overflow 3ompare instructions to set condition codes
without &eepin$ the result Each instruction can %e conditional
Top ? %its of instruction word4 condition value
3an avoid %ranches over sin$le instructions
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
80/93
The Inte" !'# ISA§2!=
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
81/93
Chapter 2 — Instructions: Language of the Computer — '*
The Inte" !'# ISA
Evolution with %ac&ward compati%ility @8@8 )!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
82/93
Chapter 2 — Instructions: Language of the Computer — '2
The Inte" !'# ISA
Vurther evolution i?@ )!
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
83/93
Chapter 2 — Instructions: Language of the Computer — '3
The Inte" !'# ISA
,nd further ,MD? )2885*4 e#tended architecture to ? %its EM?T F E#tended Memory ? Technolo$y )288?*
,MD? adopted %y Intel )with refinements* ,dded SSE5 instructions
Intel 3ore )288* ,dded SSE? instructions- virtual machine support
,MD? )announced 288=*4 SSE instructions Intel declined to follow- instead
,dvanced \ector E#tension )announced 288@*
+on$er SSE re$isters- more instructions If Intel didnJt e#tend with compati%ility- its
competitors would Technical ele$ance U mar&et success
0asic !'# $egisters
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
84/93
Chapter 2 — Instructions: Language of the Computer — '4
0asic !'# $egisters
0asic !'# A%%ressing Mo%es
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
85/93
Chapter 2 — Instructions: Language of the Computer — '5
0asic !'# A%%ressing Mo%es
Two operands per instructionSource/dest operand Second source operand
0e$ister 0e$ister
0e$ister Immediate
0e$ister Memory
Memory 0e$ister Memory Immediate
Memory addressin$ modes ,ddress in re$ister
,ddress G 0%ase displacement
,ddress G 0%ase 2scale 6 0inde# )scale G 8- !- 2- or 5*
,ddress G 0%ase 2scale 6 0inde# displacement
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
86/93
Imp"ementing IA132
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
87/93
Chapter 2 — Instructions: Language of the Computer — '&
Imp"ementing IA 32
3omple# instruction set ma&es
implementation difficult Hardware translates instructions to simpler
microoperations
Simple instructions4 !F! 3omple# instructions4 !Fmany
Microen$ine similar to 0IS3
Mar&et share ma&es this economically via%le 3ompara%le performance to 0IS3
3ompilers avoid comple# instructions
A$M ,' Instructions§2!@
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
88/93
A$M ,' Instructions
In movin$ to ?1%it- ,0M did a complete
overhaul ,0M v@ resem%les MI'S
3han$es from v=4 7o conditional e#ecution field Immediate field is !21%it constant Dropped load/store multiple '3 is no lon$er a '0
'0 set e#panded to 52 ,ddressin$ modes wor& for all word si(es Divide instruction Branch if e.ual/%ranch if not e.ual instructions
Chapter 2 — Instructions: Language of the Computer — ''
0ealStuff4,0M
v@)?
1%it*Instructio
ns
a""acies§2!<V
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
89/93
Chapter 2 — Instructions: Language of the Computer — ')
a""acies
'owerful instruction ⇒ hi$her performance Vewer instructions re.uired But comple# instructions are hard to implement
May slow down all instructions- includin$ simple ones
3ompilers are $ood at ma&in$ fast code from simple
instructions
"se assem%ly code for hi$h performance But modern compilers are %etter at dealin$ with
modern processors More lines of code ⇒ more errors and less
productivity
Vallacies
and'itfalls
a""acies
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
90/93
Chapter 2 — Instructions: Language of the Computer — )+
a ac es
Bac&ward compati%ility ⇒ instruction set
doesnJt chan$e But they do accrete more instructions
#@ instruction set
Pitfa""s
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
91/93
Chapter 2 — Instructions: Language of the Computer — )*
Se.uential words are not at se.uential
addresses Increment %y ?- not %y !
eepin$ a pointer to an automatic varia%le
after procedure returns e$- passin$ pointer %ac& via an ar$ument 'ointer %ecomes invalid when stac& popped
Conc"u%ing $emars§2283
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
92/93
Chapter 2 — Instructions: Language of the Computer — )2
g
Desi$n principles! Simplicity favors re$ularity
2 Smaller is faster
5 Ma&e the common case fast
? ood desi$n demands $ood compromises +ayers of software/hardware
3ompiler- assem%ler- hardware
MI'S4 typical of 0IS3 IS,s cf #@
3oncludin$0em
ar&s
-
8/17/2019 Chapter 02 Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design) 5th Edition
93/93