L1 - Instructions - Intro - Operations - Operands of The Computer
L1 - Instructions - Intro - Operations - Operands of The Computer
THE COMPUTER
INTRODUCTION
To command a computer’s hardware, one must speak its language
The words of a computer’s language are called instructions, and its
vocabulary is called an instruction set
The languages of computers would be as diverse as those of people
In reality computer languages are quite similar
This similarity occurs because all computers are constructed from
hardware technologies based on similar underlying principles
There are a few basic operations that all computers must provide
Further, the computer designers have a common goal:
Finding a language that makes it easy to build the hardware and the
compiler
While maximizing performance and minimizing cost and power
OPERATIONS OF THE COMPUTER
HARDWARE
ARM assembly language notation
ADD a, b, c
Instructs a computer to add the two variables b and c
and to put their sum in a
Each ARM arithmetic instruction performs only one
operation and must always have exactly three variables
Sequence of instructions adding four variables:
ADD a, b, c # The sum of b and c is placed in a.
ADD a, a, d # The sum of b, c, and d is now in a.
ADD a, a, e # The sum of b, c, d, and e is now in a.
Thus, it takes three instructions to sum the four variables
OPERATIONS OF THE COMPUTER
HARDWARE (2)
Number of operands for an operation like addition is three:
The two numbers being added together and a place to put
the sum
Requiring every instruction to have exactly three operands,
no more and no less, conforms to the philosophy of
keeping the hardware simple
Hardware for a variable number of operands is more
complicated than hardware for a fixed number
Design principle 1: Simplicity favors regularity
Regularity makes implementation simpler
OPERATIONS OF THE COMPUTER
HARDWARE (2)
Compiling simple C Assignment Statements into ARM
a = b + c;
d = a – e;
ARM code produced by a compiler
ADD a, b, c
SUB d, a, e
Compiling a Complex C Assignment into ARM
f = (g + h) – (i + j);
The compiler must break this statement into several
assembly instructions
Since only one operation is performed per ARM
instruction
COMPILED ARM CODE
f = (g + h) – (i + j);
This time we use the proper offset for byte addressing in the
load word instruction to select A[8], and the add instruction
places the sum in r5
LDR r5,[r3, #32] ; Temporary register r5 gets A[8]
For example, to add the constant 4 to register r3, we could use the
code
LDR r5, [r1, #AddrConstant4] # r5 = constant 4
ADD r3, r3, r5 # r3 = r3 + r5 (r5 == 4)
r1 + AddrConstant4 is the memory address of the constant 4