Professional Documents
Culture Documents
January 2017
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 2/83
Contents
This is the first of around 10–12 large sets of slides that will
be used for Section 01 lectures in ENCM 369 in Winter 2017.
It will usually take several lectures to get through a single set
of slides. For example, I expect that it will take about
5 21 lectures to get through this first set.
Reading these slides online is not a good substitute for
attending lectures—in most lectures I will do some important
hand-written work using the document camera. Please come
to lectures prepared to take some notes.
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 5/83
Typographical conventions
Either bold text or bright red text will be used for emphasis.
The typewriter font will usually be used for code in
assembly language, C, or C++. (I might not use the typewriter
font for code if it makes the code too wide to fit in a slide.)
Text in a box is a general description of what could appear
within a piece of code.
Example: A C do statement has this syntax . . .
do
statement
while ( expression );
(Usually statement is a compound statement that starts
with { and ends with } .)
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 6/83
Main
Bus
Memory
I What is a bus?
I What is the role of the
processor?
Processor
I/O
Device
.. ..
. .
I/O
Device
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 9/83
Main
Bus
Memory I What does I/O stand
for?
I What are examples of
Processor
I/O devices in laptop or
I/O desktop computers?
Device
.. ..
I What are examples of
. . I/O devices in
embedded computers?
I/O
Device
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 10/83
Main memory
Bytes
A register is a storage
location for one or more bus
main
bytes (typically a group memory
of two, four, or eight
bytes) inside the processor
processor. registers
I/O
So registers are NOT device
part of main memory, .. ..
. .
because main memory is
external to the I/O
processor. device
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 16/83
Registers (Review)
A register is a storage
location for one or more bus
main
bytes (typically a group memory
of two, four, or eight
bytes) inside the processor
processor. registers
I/O
So registers are NOT device
part of main memory, .. ..
. .
because main memory is
external to the I/O
processor. device
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 26/83
MIPS processors
Variations of MIPS
In this course, we’ll study the MIPS-32 version. We’ll just say
“MIPS” in this course, but we really mean MIPS-32. In
MIPS-32 . . .
I GPRs are 32 bits wide.
11
00
Each word is four word byte offset
00
11
bytes—the address address +3 +2 +1 +0
00
11
of a word is the 232 − 4 byte Z
lowest of the 232 − 8
addresses of its 232 − 12
bytes. .. ..
. .
000
111
111111111
000000000
What are the
000
111
byte Y
000000000
111111111
addresses of word 8
000000000
111111111
X, byte Y, and 4 word X
byte Z? 0
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 36/83
byte offset
word address +3 +2 +1 +0
..
. 11
00
00
11
..
.
000000011
00
4 consecutive
1111111
4,194,320
0000000
1111111
4,194,316 bytes, but NOT
4,194,312 000000000
111111111
000000000
111111111
a word
000000000
111111111
4,194,308 a word
4,194,304
.. ..
. .
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 40/83
Let’s call this example (1): Add values of GPR 8 and GPR 9,
copy result into GPR 17.
The bit pattern for this example instruction . . .
000000_01000_01001_10001_00000_100000
What do the groups of bits within the instruction mean?
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 50/83
Example (2): Add constant 1025 and value of GPR 18, copy
result into GPR 10.
Example (3): Copy word of memory pointed to by GPR 4 into
GPR 8. (This is called a “load word” instruction.)
Example (4): Copy byte of memory pointed to by GPR 4 into
GPR 8. (This is called a “load byte” instruction.)
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 51/83
Assembly Language
Let’s start with some names and uses for MIPS GPRs.
$0 is also known as $zero. It has unique, possibly surprising
behaviour: It always contains the number 0, regardless of what
is done with it.
Suppose $16 and $17 contain values 20 and 30. What
happens as a result of these instructions?
Labels in A.L.
The style of Example 1 uses the least vertical space. The style
of Example 2 may be more readable because the label is easier
to spot.
The style of Example 3 is silly but allowed by the assembler.
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 71/83
j label
meaning: goto label
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 73/83
Using the terms target and taken, what are more precise
descriptions of Step 2 for MIPS j, beq, and bne instructions?
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 75/83
sum = 0;
i = 0; variable type GPR
while (i != n) { a int * $s0
sum += a[i]; n int $s1
i++; sum int $s2
} i int $s3
// ... more code ...
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 76/83
slt means “set on less than”. In the example, if $s0 < $s1,
$t0 gets a value of 1, otherwise $t0 gets 0.
slt is a kind of comparison instruction.
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 77/83
Example pseudoinstruction . . .
blt $s0, $s1, L1
MIPS does not have a single instruction that can do both a
“less than” comparison and a branch decision.
What does the assembler do with this blt pseudoinstruction?
In ENCM 369 we want to learn real instructions, so we’ll avoid
pseudoinstructions whenever possible. However, certain
pseudoinstructions—for example, la, used in Lab 2—are
impossible to avoid.
ENCM 369 Winter 2017 Slide Set 1 for Lecture Section 01 slide 81/83