CS 301 - Assembly Language

Meets MWF 3:30-4:30 PM
Room 106 Chapman Building
University of Alaska Fairbanks

CS F301-F01
3.0 Credits, Fall 2012
Prerequisite: CS 201 (Programming)

Instructor: Dr. Orion Lawlor
lawlor@alaska.edu, 474-7678
Office: 201E Chapman
Office Hours: 11:30-1:00 TR (plus!)

Utterly Optional Textbook:
Introduction to 80x86 Assembly Language and Computer Architecture
Richard Detmer
(2nd edition includes 64-bit)

Course Website: http://www.cs.uaf.edu/2012/fall/cs301/

ADA Compliance: I will work with the Office of Disability Services (208  WHITAKER BLDG, 474-5655) to provide reasonable accommodation to students with  disabilities.

Course Goals and Requirements

By the end of the course, you will understand how your code actually executes on a real machine: from electrons on a semiconductor, to registers and binary arithmetic, to machine code and assembly, to C++ source code.  Understanding this process is useful for debugging code, and making your code faster, smaller, and more secure. This course will focus on the middle levels of this chain of abstractions--you'll eventually learn much more about the lower levels (electrons, semiconductors, logic circuits) in EE 341 & CS 441, and about the higher levels (languages, compilers, OS) in CS 331 & 321.  To understand this course, you will have to be comfortable with all the basics of C or C++: variables, loops, arrays, pointers, classes, and functions. 


No class (Labor Day): Monday, September 3.
Last day to drop: Friday, September 14. 
Midterm: 3:30pm Wednesday, October 18. 
Last day to withdraw: Friday, October 26. 

Pre-Thanksgiving optional lecture:  Wednesday,  November 21.
Thanksgiving break (no class): Friday,  November 23.
Last day of class: Monday, December 10.
Final Exam: 3:15-5:15 PM Friday, December 14. 

Student Resources

Academic Help: Rasmuson Library, Academic Advising Center (509 Gruening, 474-6396), Math Lab (Chapman Room 305), English Writing Center (801 Gruening Bldg).


Your work will be evaluated on technical correctness, rationale, and insight.  Your grade is computed from four categories of work:

  1. HW: Homeworks and machine problems, typically one batch per week throughout the semester.

  2. PROJ: Two sizable class projects--big programs written in, or relating to assembly, with a short in-class presentation.

  3. MT: Midterm Exam

  4. FINAL: Final Exam (comprehensive)

The final score is then calculated as:

TOTAL = 30% HW + 20% PROJ + 25% MT + 25% FINAL

This percentage score is transformed into a plus-minus letter grade via these cutoffs: A >= 93%; A- 90%; B+ 87%; B 83%; B- 80%; C+ 77%; C 70%; D+ 67%; D 63%; D- 60%; F. The grades “C-”, “F+”, and “F-” will not be given. “A+” is reserved for truly extraordinary work. At my discretion, I may round your grade up if it is near a grading boundary. Grades for each assignment and test may be curved upward by linear scaling, but this is almost never needed.

Homeworks are due by midnight at the end of the day they are due. Late homeworks will receive no grade credit, but you'll sleep better knowing you did them anyway. At my discretion, I may allow late work without penalty when due to circumstances beyond your control, such as attacks by wild animals (“the dog ate my homework” is not acceptable; while “wolves ate my face” may be).

Plagiarism: Everything you turn in must be your own work--violations of the UAF Student Code of Conduct will result in a minimum penalty equal to THAT ENTIRE SECTION OF YOUR GRADE (e.g., one plagiarized homework question will negate an otherwise perfect grade on all homeworks). However, even substantial reuse of other people's work is fine (and not plagiarism) iff it is clearly cited; you'll be graded on what you've added to others' work. Group projects (NOT homeworks) are acceptable iff you clearly label who did what work; but I do expect a two-person project to represent twice as much work as a one-person project.

Department policy does not allow tests to be taken early; but when necessary I may allow them to be taken late. In extraordinary circumstances, such as an ice storm or zombie outbreak, classes may be held electronically via Blackboard/Elluminate Live.

Course Outline (Tentative)


Data representation

  • Bits--counting, bitwise operations

  • Binary, decimal, hex, octal, and base conversion

Table driven programming

  • Storing operations in a simple array

  • Machine code: a binary table of operations

Assembly language

  • Concept of registers: store stuff here

  • Opcodes: do this now

  • Branches and control flow flags

  • if”, “while” and “for” in assembly

    • Solving the empty loop problem

Memory access

  • Pointer arithmetic in C/C++. C++ void *

  • Pointers, arrays, and strings in assembly.

  • Classes and structs in assembly. offsetof

  • Stack push and pop. malloc and free.

  • Segmented DOS memory, 16-bit code, and the PC boot block.


Function calls in assembly

  • Function calling conventions, saved registers.

  • jmp versus call instructions. Tail recursion.

  • extern “C” and calling assembly from C++

  • Linkers and link errors

  • C++ virtual methods and the vtable

  • Syscalls and the OS

Arithmetic operations and overflow

  • Bitwise operations: AND, OR, XOR

  • Bit shifting (<< and >>), using AND for masking

  • "SIMD Within A Register" (SWAR), like Cohen-Sutherland clipping

  • Dynamic binary translation: generating machine code at runtime

  • Integer Overflow.  Wraparound.  Range.

  • Subtraction: two's complement addition; the sign bit.

  • addc” and multi-precision integer arithmetic.

Project 1 presentations in class

Midterm exam

(Midterm to Thanksgiving)

Performance and Optimization

  • General optimization checklist

    • Timing and profiling

    • Algorithmic Optimization

    • Invariant hoisting, constant propagation

  • Memory Performance

    • Caching

    • Levels & performance of cache

    • Program transformations to improve memory performance

  • Concurrency

    • Hardware and Software Pipelining

    • Cost of branches

    • Multicore code with OpenMP

    • Cautions about locking and consistency

(Thanksgiving to End)

Floating point

  • Assembly language FPU Instructions (movss, addss)

  • IEEE floating-point representation

    • Sign, exponent, mantissa

    • normalization, roundoff

    • Fun bitwise hacks (fast absolute value, log-base-2, float-to-int, etc.)

    • denormalized numbers, NaNs, and performance penalty

  • 4-vector of floating point numbers (movups, addps)

    • x86 SSE & <mmintrin.h> intrinsics

    • Graphics card GLSL

Project 2 presentations in class

Final exam