没有合适的资源?快使用搜索试试~ 我知道了~
Chapter6_新旧对比2
资源详情
资源评论
资源推荐
6
Architecture
6.1 INTRODUCTION
The previous chapters introduced digital design principles and building
blocks. In this chapter, we jump up a few levels of abstraction to define
the architecture of a computer. The architecture is the programmer’s view
of a computer. It is defined by the instruction set (language) and operand
locations (registers and memory). Many different architectures exist, such
as ARM, x86, MIPS, SPARC, and PowerPC.
The first step in understanding any computer architecture is to learn
its language. The words in a computer’s language are called instructions.
The computer’s vocabulary is called the instruction set. All programs run-
ning on a computer use the same instruction set. Even complex software
applications, such as word processing and spreadsheet applications, are
eventually compiled into a series of simple instructions such as add, sub-
tract, an d branch. Computer instructions indicate both the operation to
perform and the operands to use. The operands may come from
memory, from registers, or from the instruction itself.
Computer hardware understands only 1’sand0’s, so instructions are
encoded as binary numbers in a format called machine language. Just as
we use letters to encode human language, computers use binary numbers
to encode machine language. The ARM architecture represents each instruc-
tion as a 32-bit word. Microprocessors are digital systems that read and
execute machine language instructions. However, humans consider reading
machine language to be tedious, so we prefer to represent the instructions
in a symbolic format called assembly language.
The instruction sets of different architectures are more like different
dialects than different languages. Almost all architectures define basic
instructions, such as add, subtract, and branch, that operate on memory
or registers. Once you have learned one instruction set, understanding
others is fairly straightforward.
6.1 Introduction
6.2 Assembly Language
6.3 Programming
6.4 Machine Language
6.5 Lights, Camera, Action:
Compiling, Assembling, and
Loading*
6.6 Odds and Ends*
6.7 Evolution of ARM
Architecture
6.8 Another Perspective: x86
Architecture
6.9 Summary
Exercises
Interview Questions
+
+
−
Physics
Devices
Analog
Circuits
Digital
Circuits
Logic
Micro-
architecture
Architecture
Operating
Systems
Application
Software
>”hello
world!”
295
The “ARM archit ecture” we
describe is ARM version 4
(ARMv4), which forms the
core of the instruction set.
Section 6.7
summarizes new
features in versions 5–8ofthe
architecture . The ARM
Architecture Refer ence
Manual (ARM), available
online, is the authoritative
definition of the architecture .
A computer architecture does not define the underlying hardware
implementation. Often, many different hardware implementations of a
single architecture exist. For example, Intel and Advanced Micro Devices
(AMD) both sell various microprocessors belonging to the same x86
architecture. They all can run the same programs, but they use different
underlying hardware and therefore offer trade-offs in performance, price,
and power. Some microprocessors are optimized for high-performance
servers, where as others are optimized for long batter y life in laptop com-
puters. The specific arrangement of registers, memories, ALUs, and other
building blocks to form a microprocess or is called the microarchitecture
and will be the subject of Chapter 7. Often, many different microarchitec-
tures exist for a single architecture.
In this text, we introduce the ARM architecture. This architecture was
first developed in the 1980s by Acorn Computer Group, which spun off
Advanced RISC Machines Ltd., now known as ARM. Over 10 billion
ARM processors are sold every year. Almost all cell phones and tablets
contain multiple ARM processors. The architecture is used in everything
from pinball machines to cameras to robots to cars to rack-mounted
servers. ARM is unusual in that it does not sell processors directly, but rather
licenses other companies to build its processors, often as part of a larger sys-
tem-on-chip. For example, Samsung, Altera, Apple, and Qualcomm all build
ARM processors, either using microarchitectures purchased from ARM or
microarchitectures developed internally under license from ARM. We
choose to focus on ARM because it is a commercial leader and because the
architecture is clean, with few idiosyncrasies. We start by introducing assem-
bly language instructions, operand locations, and common programming
constructs, such as branches, loops, array manipulations, and function calls.
We then describe how the assembly language translates into machine lan-
guage and show how a program is loaded into memory and executed.
Throughout the chapter, we motivate the design of the ARM archi-
tecture using four principles articulated by David Patterson and John
Hennessy in their text Computer Organization and Design: (1) regularity
supports simplicity; (2) make the common case fast; (3) smaller is faster;
and (4) good design demands good compromises.
6.2 ASSEMBLY LANGUAGE
Assembly language is the human-readable representation of the compu-
ter’s native language. Each assembly language instruction specifies both
the operation to perform and the operands on which to operate. We
introduce simp le arithmetic instructions and show how these operations
are written in assembly language. We then define the ARM instruction
operands: registers, memory, and constants.
This chapter assumes that you already have some familiarity
with a high-level programming language such as C, C++, or Java.
296
CHAPTER SIX Architecture
(These languages are practically identical for most of the examples in this
chapter, but where they differ, we will use C.) Appendix C provides an
introduction to C for those with little or no prior programming
experience.
6.2.1 Instructions
The most common operation computers perform is addition. Code
Example 6.1 shows code for adding variables
b and c and writing the
result to a. The code is shown on the left in a high-level language (using
the syntax of C, C++, and Java) and then rewritten on the right in ARM
assembly language. Note that statements in a C program end with a
semicolon.
The first part of the assembly instruction,
ADD,iscalledthemnemonic and
indicates what operation to perform. The operation is performed on
b and c,
the source operands, and the result is written to
a,thedestination operand.
Code Example 6.2 shows that subtraction is similar to addition. The
instruction format is the same as the
ADD instruction except for the opera-
tion specification,
SUB. This consistent instruction format is an example of
the first design principle:
Design Principle 1: Regularity supports simplicity.
Instructions with a consistent number of operands—in this case, two
sources and one destination—are easier to encode and handle in hard-
ware. More complex high-level code translates into multiple ARM
instructions, as shown in Code Example 6.3.
In the high-level language examples, single-line comments begin with
// and continue until the end of the line. Multiline comments begin with
/* and end with */. In ARM assembly language, only single-line comments
We used Keil’s ARM
Microcontroller Development
Kit (MDK-ARM) to compil e,
assemble, and simulate the
example assembly code in this
chapter. The MDK-ARM is a
free de velopmen t to ol that
comes with a complete ARM
compiler. Labs available on
this textbook’s c ompani on site
(see Pr eface) show how to
install and use this tool to
write, compil e, simul ate, and
debug both C and assembly
programs.
Code Example 6.1 ADDITION
High-Level Code
a = b + c;
ARM Assembly Code
ADD a, b, c
Code Example 6.2 SUBTRACTION
High-Level Code
a = b − c;
ARM Assembly Code
SUB a, b, c
Mnemonic (pronounced
ni-mon-ik) comes from the
Greek w ord μιμνΕσκεστηαι,to
remember. The assembly
language mnemonic is easier
to remember than a machine
language pattern of 0’sand1’s
representing the same
operation.
6.2 Assembly Language 297
are used. They begin with a semicolon (;) and continue until the end of
the line. The assembly language program in Code Example 6.3 requires a
temporary variable
t to store the intermediate result. Using multiple
assembly language instructions to perform more complex operations is an
example of the second design principle of computer architecture:
Design Principle 2: Make the common case fast.
The ARM instruction set makes the common case fast by including
only sim ple, commonl y used instructions. The number of instructions is
kept small so that the hardware required to decode the instruction and
its operands can be simple, small, and fast. More elaborate operations
that are less common are performed using sequences of multiple simple
instructions. Thus, ARM is a reduced instruction set computer (RISC)
architecture. Architectures with many complex instructions, such as
Intel’s x86 architecture, are complex instruction set computers (CISC).
For example, x86 defines a “string move” instruction that copies a string
(a series of characters) from one part of memory to another. Such an
operation requires many, possibly even hundreds, of simple instructions
in a RIS C machine. However, the cost of implementing complex instru c-
tions in a CISC architecture is added hardware and overhead that slows
down the simple instructions.
A RISC architecture mini mizes the hardware complexity and the neces-
sary instruction encoding by keeping the set of distinct instructions small.
For example, an instruction set with 64 simple instructions would need
log
2
64 = 6 bits to encode the operation. An instruction set with 256 com-
plex instructions would need log
2
256 = 8 bits of encoding per instruction.
In a CISC machine, even though the complex instructions may be used only
rarely, they add overhead to all instru ctions, even the simple ones.
6.2.2 Operands: Registers, Memory, and Constants
An instruction operates on operands. In Code Example 6.1, the variables
a, b,andc are all operands. But computers operate on 1’s and 0’s, not
variable names. The instructions need a physical location from which to
retrieve the binary data. Operands can be stored in registers or memory,
or they may be constants stored in the instruction itself. Computers use
Code Example 6.3 MORE COMPLEX CODE
High-Level Code
a = b + c − d; // single-line comment
/* multiple-line
comment */
ARM Assembly Code
ADD t, b, c ; t = b + c
SUB a, t, d ; a = t − d
298 CHAPTER SIX Architecture
剩余89页未读,继续阅读
内酷少女
- 粉丝: 16
- 资源: 302
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0