asee-2009-arch1x - Robust Autonomic Systems

Download Report

Transcript asee-2009-arch1x - Robust Autonomic Systems

A Gentle Introduction to Addressing
Modes in a First Course in
Computer Organization
Dr. Eric Freudenthal
Brian A. Carter, Frederick Kautz, Alexandria Ogrey
October , 2008
Motivation to modify computer org course:
Students could no longer program in C

But we could. Why?

Principal CS teaching languages




Pascal (or some other procedural language)
Featured explicit memory management (i.e., pointers)
Forced explicit management of compiler and linker
Connections to machine organization obvious


Similar memory semantics
Only conceptual leap was in structured control-flow


Note that FORTRAN didn’t require this leap
Understanding C requires familiarity with:

Separate compilation


symbols, matching types, etc.
Memory management
What necessary?
Java as Principal Teaching Language

This is not a rant against Java


Java’s differs substantially from machine organization




Global variables are “hidden” within classes
Automatic garbage collection
Methods live within objects
Tools hide “systems” issues



We’re proposing a response
IDEs (students don’t learn/understand separate compilation)
Students don’t understand the roles of linker, symbol scope, etc.
Students are “exposed” to C in a language survey course

But, C’s semantics are best understood in the context of architecture
Why should we care?

Upper-division “systems” courses


Students don’t know how to program in C
Students unfamiliar with key “systems” components


linker, libraries, etc.
Employers unhappy


CS students no longer understood runtime issues
And therefore were ill prepared to learn C!
Our Approach



Leave introductory sequence unchanged
 CS I, II, and III remain Java-based
Interleave instruction in C and computer organization (over one semester)
 Introduce students to the key concepts in C
 Then use assembly/machine language to show how it’s implemented
Students seem to “get it”
 Understand the relationship of OO memory & method abstractions to
runtime
 Students are able to learn (and even derive) compilation techniques


We’ll show you a few pedagogical tricks that seem to work later
The first group of students are now attending a senior-level OS course

Much stronger skills are observed
New: Teaching Trick 1 (NEW):
Incrementally introduce addressing modes
Begin with only absolute addressing
1.
Instruction
Nibble2
Nibble1
Extension Word 1
Address of source
operand
Format:
Low
nibble
2
9
2
mov &src, &dst Operation
 For MSP430 – can even delay introducing registers!!

High nibble
Extension Word 2
Address of dest.
operand
Students translate increasingly complex statements:
2.
Provide lots of opportunity to practice using only absolute
addressing (and scalar types)

Teach pointers late
3.
Introduce registers, then only one indirect mode
1.


2.
Relate to C arrays and structs; reference types
Provide lots of opportunity for practice
Then teach rest of the addressing modes as optimizations
Teaching Trick 2:
Reduction to goto C (FORTRAN)


goto is legal in C
First: perform a manual transformation



Students first translate for, while, etc. to goto C
Conversion of goto C to assembly language is trivial
After, in an assignment, students produce standard
transformation templates
Block-structured
C source code
if (x!=3)
y = x;
else
y = 3;
goto C
Assembly Language
.data
three: .word 3
.text
if (x==3) goto x3_else
cmp &three, &x
jnz x3_else
y = x
mov &x, &y
goto x3_end;
jmp x3_end
x3_else:
x3_else:
y = 3;
mov &three, &y
x3_end:
x3_end:
Teaching Trick 3:
Introduction of Operator (Parse) Trees

First: challenge students to translate arithmetic
expressions to assembly language


Have them “own the challenge”
Next introduce operator trees
Expression
d = a + b / 2;
Parse Tree
=
Assembly
.data
+ (t1)
t1: .word
d
÷ (t1) t2: .word
(t2)*
.text
mov &b, &t1
b 2
rra &t1
c 2
mov &c, &t2
add &t2, &t2
add &t1, &t2
mov &t1, &d
;
;
;
;
;
;
t1 = b
t1 = b/2
t2 = c
t2 = c*2
t1 += t2
d = t1
Teaching Trick 3:
Two-pass Assembly


Motivate the problem with an exercise
Solve the problem by reserving space for operands in the
first pass
Lab Course

Students first learn UNIX tools


Editor, shell, make
Students write C programs that expose:

Variable types (scalar, array, pointer) & access modes






Access modes related to addressing modes
Pointers
Shifts & masks
Students write leaf routines (called by C) in assembly
language
Students call C routines from assembly language
Students learn how interrupts work
Embedded Target System




MSP430 low-power embedded controller
Twenty-seven instructions
$20 for full development system
Works with completely free open-source GNU tools

Exposes students to how tools work
Tools

SVN (version control system) to manage assignments


Entire repository accessible to TA & instructor
Separate subdir for each student


Students “collaborate” with selves & TA




Separate subdir for each project
Avoids carrying files around on USB stick
Repository tracks commit dates
TA can obtain or “peek” at project, can leave comments
Gcc, gas, ld, make, gdb, emacs


Students required to learn emacs
Exposes how IDEs work