120 likes | 248 Views
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?
E N D
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 • We’re proposing a response • Java’s differs substantially from machine organization • Global variables are “hidden” within classes • Automatic garbage collection • Methods live within objects • Tools hide “systems” issues • 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 • Format: mov &src, &dst • For MSP430 – can even delay introducing registers!! • Students translate increasingly complex statements: • Provide lots of opportunity to practice using only absolute addressing (and scalar types) • Teach pointers late • Introduce registers, then only one indirect mode • 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 gotoC (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 goto C Assembly Language if (x!=3) y = x; else y = 3; if (x==3)goto x3_else y = x gotox3_end; x3_else: y = 3; x3_end: .data three: .word 3 .text cmp &three, &x jnzx3_else mov &x, &y jmpx3_end x3_else: mov&three, &y 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 Parse Tree Assembly .data t1: .word t2: .word .text mov&b, &t1; t1 = b rra&t1; t1 = b/2 mov &c, &t2 ; t2 = c add &t2, &t2 ; t2 = c*2 add &t1, &t2 ; t1 += t2 mov &t1, &d ; d = t1 d = a + b / 2; = (t1) + d (t1) ÷ (t2) * b 2 c 2
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 • Separate subdir for each project • Students “collaborate” with selves & TA • 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