Instructions

Download Report

Transcript Instructions

CS 300 – Lecture 6
Intro to Computer Architecture
/ Assembly Language
Instructions
Reading
We're in Chapter 2 of the text:
* 2.1 – 2.7 should be read by Thursday
Homework 3
Let's take a look …
Inside a Computer
Places to store data:
* registers: high speed memory in a processor.
Very fast to access but not many of them. Usually
1 clock to access.
* main memory: takes a LOT longer to get to this
(hundreds of clocks) but lots more of it. Every
word in memory has an address of some fixed size
(30 bits for MIPS, byte addressable)
* Cache: "invisible" memory elements between the
registers and main memory.
Doing Things
An instruction is a piece of data that, when
executed, causes the processor to do
something.
Different processors have different
instruction sets.
There's no way to tell the difference between
an instruction and other data in a program –
an instruction is an interpretation of the 0s
and 1s in memory.
Instruction Formats
We usually understand an instruction as a
combination of things:
* An operation: what it does
* Data reference: which data it uses
* Sequencing: what happens next
All of this is encoded in binary, usually as a
set of variously sized fields of a word.
Software
An "assembler" is a program that converts a
textual representation of an instruction into a
binary one. Plus lots of other things. The
key idea: you know EXACTLY what will
happen when executing an assembly
language program.
Software
A "compiler" is a program that converts a
programming language like Java or C into
assembly language.
A "High Level" language is one that is very
different from the assembly language and is
generally not predictable in some ways.
A "Low Level" language is one that is very close to
the basic machine capabilities and will have a very
predictable behavior. Our low level language will
be "C".
Referencing Data
Instructions need to indicate which data is
being operated on. The MIPS is a "three
address machine" – that is, each instruction
has (usually) 2 inputs and one output. So
a=b+c
is something you can do with a single
instruction (sort of).
We represent instructions like this:
add a,b,c
# a=b+c
Compiling Expressions
In a programming language, we use expression
trees:
a = (b+c)*(4-d)
e = e – f*g
In instructions, these have to be broken down into
a series of instructions that each do just one thing.
Temporary variables hold intermediate results.
In MIPS, instructions must refer to registers
(notated as $r in the text).
Compiling Expressions
a = (b+c)*(4-d)
t1 = b+c
t2 = 4-d
a = t1*t2
e = e – f*g
t3 = f*g
e = e – t3
Deciding which register
will hold each variable
or temporary is "register
allocation"
Referencing Memory
This is ESSENTIAL! If register "A" has a memory
address in it, we can read the value of the word
that A "points to" using an instruction.
We can further modify the memory address by
adding an constant to the memory address in the
register – this is really common! Terms:
base address: the "original" memory address
offset: a constant added to the address
Laying Out Data Structures
* Arrays: data is stored in sequential
memory addresses – locations are
computed by doing subscript arithmetic. All
data is the same size.
* Records (objects): data is stored in a fixed
sized block of memory. Each field is in a
known place in the memory. If we know the
base address of the object, we know where
to find every field.