Document

Report
CS 215
Introduction to Assembly Language
and Computer Architecture
Course topics

Computer Organization




Computer Components
 CPU, memory, I/O devices, bus
Representing information
 Integers, real numbers, text characters,
machine code
Arithmetic operations
Assembly Language





Basic features
Translation (C  assembly language)
Data structures
Procedures
I/O Operations
Course activities

Computer Organization

Representing information

Encode and decode various types of data



How is 3.14 represented by a computer?
What unsigned integer is represented by the byte
11001010?
Arithmetic operations

Demonstrate the
(addition/subtraction/multiplication/division) of
two (integers/real numbers) using one of the
algorithms for hardware operations presented in
class

Requires an understanding of the representations
Course activities

Assembly Language

Translation (C++  assembly
language)


Implement a C++ code fragment in
assembly language
Procedures

Implement a C++ function in assembly
language


Use activation records
Programmed I/O

Write code which manages I/O to a device

monitor, keyboard
Focus: MIPS R2000 Assembly
Language


The MIPS R2000 is an old CPU from SGI
 Modern MIPS used in SGI workstations, Sony
PS2
 All MIPS chips use nearly the same assembly
language
 MIPS assembly language is very similar to that
of the PowerPC chip, the heart of the Apple
Macintosh
Why MIPS R2000
 Simple, easily learned language
 Straight-forward architecture
 Freely available simulator: SPIM
Why study assembly language?


Developing a more accurate model
of computation is the main goal of
this course
A software engineer who
understands how a computer works
will be able to:



design more efficient code
program for devices other than PCs
Better understand hardware, OS,
libraries, network, source code, etc.
What is a model?

A model is a partial representation
of a system



incomplete
specific purpose
Multiple models for different
purposes

Model of the city of Milwaukee for
MCTS bus driver
 MMSD engineer
 Bicyclist
 Commercial airline pilot

Level of detail

Eliminating distracting detail enables
focus on aspects of interest, get higher
level perspectives


street maps for navigation do not show
buildings and topography
More detail is NOT necessarily better


A detailed schematic of a car engine would not
help the average motorist troubleshoot a
sputtering engine
 A flow chart would be better
A city map that shows every alley is less useful
to a visitor than one that shows just major
roads
Abstraction

Modeling is about abstraction:


Models often abstract away variation



building general, high-level concept pictures
Access to UWM computers requires
authentication
The authentication abstraction filters out
mechanism
 login-password, fingerprint recognition, ID
badge, etc.
Different abstractions, levels of
abstraction depending on aspects of
interest, degree of expertise
Learning is model refinement

The primary purpose of modeling is
to improve understanding

Observing differences between the
model and reality shows us gaps in our
understanding
This is how learning works, according to
educational theory
 Cognitive dissonance


Learn is updating our model to better
predict reality
Novice user’s model of
computation

A computer is a machine that:





Can generate video and sound, like a TV
responds to input from a keyboard and a mouse
 Unlike a TV
must be plugged into the Internet to work
properly
 Like a TV needs cable, or an antenna
This is a useful model for word-processing,
email, web browsing, copying CD’s, etc.
Programming requires a more detailed
model
CS-201 model of computation

A computer is a
machine that executes
a C++ program, by



Executing each line of the
program sequentially,
subject to control
structures and function
calls
Allowing the program to
receive text input from
the keyboard, or a file
Allowing the program to
produce text output to
the monitor, or a file
C++ Program
Computer
A more complex model of computation


A computer executes
machine instructions, and
can control a variety of
input/output devices
Compiler




Operating system



language definition
settings
implementation details
resource allocation
device management
CPU


machine instructions
addressing modes
C++ Program
CPU
Operating System
Compiler
Programming Language as
Abstraction


A primitive is an elementary
operation.
A primitive in a higher level of
abstraction can correspond to a set of
operations in a lower level of
abstraction. For example,



Operators of Language A: {+, -, *, /}
Operators of Language B: {+, -}
Let 5*2 be a statement in Language A.
What is its equivalent in Language B?
Monadic vs. Dyadic



For the most part, the computer
hardware is limited to executing
monadic and dyadic operations
monadic - takes a single operand,
e.g. taking the complement
dyadic - takes two operand, e.g.
adding two values
The assembly process


Ultimately, instructions written in a
higher level abstraction must be
expanded to the primitives the
hardware understands directly, the
machine language.
For example, high-level language to
assembly language using a
compiler; then from assembly
language to machine language
using an assembler
Compilers vs. Assemblers


A compiler is a computer program
that translates a high-level
language, e.g. C++, into an
intermediate-level language, e.g.
assembly language.
An assembler is a computer
program that translates an
assembly language into machine
language (string of binary digits).
Computer Architecture




Defines what the computer’s
instruction do and how they are
specified
The set of instructions determine
the computer’s capability
A computer’s machine language is
determined by its manufacturer
The assembly language is also
formally defined by the
manufacturer
SAL, MAL, TAL

SAL (Simple Abstract Language)


MAL (MIPS Assembly Language)


contains the notion of types similar to
HLL and is based on MAL
more abstract and easier to use than
TAL. The MIPS RISC assembler
translates MAL into TAL, then TAL into
MIPS RISC machine code
TAL (True Assembly Language)

exactly corresponds with hardware
operations
Computer Execution



A computer’s processor executes
instructions.
The instructions specifies how
variables are to be manipulated and
stored in memory.
A variable in the machine language
must be assigned a specific memory
location. This process of assigning a
memory location is called binding.
Example
A statement in a high-level language
(HLL)
A = B + C;
An equivalent assembly language
instruction may be
add A, B, C
 The mnemonic add stands for an
operation code (opcode) and A, B,
and C are the operands
CPU and the Memory

The Central Processing Unit (CPU)



The Main Memory



is responsible for instruction execution.
determines how the memory is to be
modified.
is a collection of cells and each cell is
assigned a label
a cell can hold a value.
CPU stores a new variable value,
fetches instructions, or loads a
variable value.
Instruction Types



There are three instruction types:
Arithmetic, Logical, and Control
Arithmetic and logical instructions
evaluate variables and assign new
values to variables
Control instructions test or compare
values of variables and make
decisions about what instruction is
going to be executed next.
Fetch-Decode-Execute Cycle
A computer’s complete functionality
is described by this mechanism.
1. instruction fetch
2. program counter (PC) update
3. instruction decode
4. operand load
5. operation execution
6. storage of results

Example
x1 = x2 + x3;
x4 = x2 - x5;
if(x4 != x1){
x1 = x1 + x5; }
else
Next part . . .
Example
part1:
add
sub
beq
add
x1,x2,x3
x4,x2,x5
x4,x1,part2
x1,x1,x5
part2:
. . .

similar documents