CS 210: Assembly Language and Systems Programming (Spring 2006)
Lecture: Mon-Wed 3:30pm-5:15pm (Room HRN-235)
Instructor:
Allan Cruse
cruse@usfca.edu
Phone: (415) 422-6562
Office: 212 Harney Science Center
Office Hours: (see my homepage)
- This course introduces students to computer programming at the
machine language level, as a means of exploring some basic concepts
of microcomputer architecture, system software and peripheral hardware.
It is comprised of lectures, readings, discussions, demonstrations,
consultations, assigned design projects and scheduled exams.
- The course will focus primarily on the assembly language for Intel
Pentium processors running the Linux operating system
and will use the GNU assembler and program development tools.
Students are presumed to have prior experience with computer programming
in at least one high-level language (such as C/C++/java), and to be familiar
with basic operating system commands (e.g., as covered in CS 110/112).
- Class meetings will be held in the
Michael D. Kudlick computer classroom
(Room 235, Harney Science Center) which affords convenient opportunities
for combining formal instruction with "hands-on" programming exercises.
This facility, a gift of USF alumnus
Alfred S. Chuang ('82), was opened in Fall 2002.
Textbooks (for collateral readings):
Robert G. Plantz,
"Introduction to x86 Assembly Language Using Linux",
Sonoma State University (2006)
prepublication manuscript in a limited edition
will be available from USF Bookstore in late January 2006
"I believe very strongly that the best programnmers have a good understanding
of how computer hardware works. I think this principle holds in most fields:
the best drivers understand how automobiles work; the best musicians
understand how their instrument works; etc. The goal of this book is to
introduce how hardware works from a programmer's point of view."
-- Robert Plantz, Sonoma State University
Kip R. Irvine,
Assembly Language Programming for Intel-Based Computers (Fourth Edition)
Prentice-Hall, Inc. (2003), ISBN 0-13-091013-9
"One of my goals is to help students approach programming problems with a
machine-level mind set... [and] give students the first-hand experience of
writing software in an environment that teaches them how the computer really
works...
The present edition includes topics that lead naturally into subsequent
courses in computer architecture, operating systems, and compiler writing."
-- Kip Irvine, Florida International University
Learning Outcomes:
- You will know the set of fundamental operations a computer can perform.
- You will know how to build complex computations out of simple operations.
- You will be able to "see through" code written in a high-level language.
- You will gain the capability to fully utilize features in modern CPUs.
- You will lay the conceptual ground for understanding later CS courses.
- You will acquire a skill-set of practical value in professional practice.
Resources
Systems Software:
- Utility program: ljpages.cpp
(a tool that submits your program source to a laser printer)
- Utility program: dump.cpp
(a tool that displays the contents of any file in hex and ascii)
- Utility program: fileview.cpp
(a navigation tool for viewing the contents of binary files)
<-- revised on 6/7/2006
- Utility program: iopl3.cpp
(a tool by Alex Fedosov that lets user programs do direct I/O)
- Device-driver: dosio.c
needed for addressing I/O ports and accessing 8086 memory
- Utility program: mmake.cpp
(a tool for compiling Linux 2.6 kernel modules)
Readings
- Week 1: Plantz, Chapter 1: Introduction;
and Irvine, Chapter 1: Basic Concepts
- Week 2: Plantz, Chapter 2: Data Storage Formats;
and Irvine, Chapter 2: IA-32 Processor Architecture
- Week 3: Plantz, Chapter 3: Computer Arithmetic;
and Irvine, Chapter 3: Assembly Language Fundamentals
- Week 4: Plantz, Chapter 4: Central Processing Unit;
and Irvine, Data Transfers, Addressing, and Arithmetic-
- Week 5: Plantz, Chapter 5: Programming in assembly language;
and Irvine, Chapter 5: Procedures
- Week 6: No new assignment; review for Midterm Exam I.
- Week 7: Plantz, Chapter 6: Computer Operations;
and Irvine, Chapter 6: Conditional Processing
- Week 8: Plantz, Chapter 7: Calling Functions;
and Irvine, Chapter 7: Integer Arithmetic
- Week 9: Plantz, Chapter 8: Program Flow Constructs;
and Irvine, Chapter 8: Advanced Procedures
- Week 10: Plantz, Chapter 9: Automatic Variables;
and Irvine, Chapter 9: Strings and Arrays
- Week 11: No new assignment; review for Midterm Exam II.
- Week 12: Plantz, Chapter 10: Writing your own Functions;
and Irvine, Chapter 12: High-Level Language Interface
- Week 13: Plantz, Chapter 11: Data Types in Assembly Language;
and Plantz, Chapter 12: Data Structures;
- Week 14: Plantz, Chapter 13: Fractional Numbers
and Irvine, Chapter 17: Advanced Topics
- Week 15: No new assignment: review for Final Examination
Handouts
- 0203-210-01: Course syllabus(.PDF)
- lesson1.ppt (Powerpoint Slides)
- Simple "high-level" programming example: demo1.c
- Example rewritten in assembler language: demo2.s
- Separate function (needed by 'demo2.s'): sprintf.s
- lesson2.ppt (Powerpoint Slides)
- Demo program: squares.cpp
a high-level language 'prototype' for the assembly language demo below
- Demo program: squares.s
showing a program-loop (in assembly) that prints out a mathematical table
- Demo program: eflags.s
shows the initial contents of the EFLAGS register as a 32-bit binary integer
- Demo program: reverse.s
showing a way to use the stack to reverse the order of stored characters
- Subroutine: eax2hex.s
(it uses the idea from 'reverse.s' to generate a hexadecimal digit-string)
- Exercise solution: esp.s
shows one possible solution to our in-class exercise (on using 'eax2hex')
- In-class exercise: gdb.ex1
introduces use of the GNU debugger to examine assembly language programs
- Demo program: xmas.s
employs some algorithms that use the Pentium's 'mul' and 'div' instructions
- Demo program: showproc.s
shows how a task may invoke system-calls to display its own memory-map
- Demo program: scanning.s
uses string-instructions to locate the mapping-information about its stack
- Subroutine: hex2eax.s
(it interprets a string of hexadecimal digits and returns its value
in register EAX)
- Demo program: app64.s
illustrating Linux assembly language programming for Intel EM64T processors
- Some test-data: easter.doc for Project #1
- Demo program: stackseg.s
an application that displays the address-range and size of its stack-segment
- Demo program: seestack.s
an application that displays the contents of its own "active" program stack
- Demo program: showvars.s
shows 'environment-variables' (using what our 'seestack' demo taught us)
- Useful subroutines: base10io.s
(for converting between a numerical value and a decimal digit-string)
- Demo program: add.s
uses routines in 'base10io.s' to show the sum of two command-line arguments
- In-class exercise: inclass2.doc
on enhancing a program that calls our 'asc2eax' and 'eax2asc' routines
- Exercise solution: add2.s
adds any number of unsigned integer arguments typed on the command-line
- Program skeleton: leapyear.s
as your starting point when answering question V on Midterm Exam I
- Problem solution: leapyear.s
shows one possible way of answering question V on Midterm Exam I
- Demo program: season.cpp
shows what mathematical calculations needed when drawing a calendar
- Demo program: summer.s
shows how three consecutive month-layouts can be horizontally displayed
- Demo program: forkdemo.s
illustrating direct use of the Linux 'fork()' and 'waitpid()' system-calls
- Demo program: execdemo.s
combines use of the Linux 'execve()' system-call with 'fork()' and 'waitpid()'
- Demo routine: softmulb.s
provides an emulation in software of the CPU's 'mul %bl' instruction
- Demo program: multest.cpp
performs exhaustive testing of our 8-bit software-multiply routine
- Experiments with 'signals':
signal1.cpp,
signal2.cpp,
signal3.cpp,
signal4.cpp,
signal5.cpp,
signal6.cpp
- Demo routine: softdivb.s
provides an emulation in software of the CPU's 'div %bl' instruction
- Demo program: divtest.cpp
performs exhaustive testing of our 8-bit software-divide routine
- Demo program: showpi.s
introduces us to use of the Pentium's floating-point instruction-set
- Demo program: distance.s
uses floating-point instructions to compute distance between two points
- Demo program: flt2asc.s
shows a single-precision floating-point number as a signed 4-place decimal
- Demo program: dbl2asc.s
shows a double-precision floating-point number as a signed 8-place decimal
- Demo program: gcdcalc.c
this example will allow us to see how a stackframe is used by C functions
- Demo program: gcdcalc.s
this is a commented version of x86 assembly produced by the gcc compiler
- Demo program: gcd.s
this is a case-study in hand-crafting some "optimized" assembly language code
- Demo program: testgcd.c
this C program calls the "optimized" version of our (external) 'gcd()' function
- Demo program: dayout.s
illustrates a 'helper-function' that might be useful for our 'calendar' project
- Demo program: firstday.cpp
shows how to find which day of the week is January first in a given year
- Demo program: watchtsc.cpp
shows a continuous display of the 'volatile' TimeStamp Counter register
- Demo program: fastgcd.s
this is an even more efficiently hand-optimized version of the 'gcd()' function
- Demo program: timedgcd.cpp
compares how many cpu-cycles are consumed by two implementations
- Problem solution: textline.s
shows one possible way of answering question V on Midterm Exam II
- Demo program: noecho.s
shows how you can supress the usual display of keys that are typed in
- Demo program: toupper.s
scans an array of ascii-codes converting lowercase letters to uppercase
- Demo program: rawtty.cpp
shows how to enable 'noncanonical' terminal control (called "raw" mode)
- Demo program: studytty.cpp
shows default-values of entries in the termios data-structure's c_c[] array
- Demo program: tty2file.s
writes the 'struct termios' data-structure to a file you can view with 'fileview'
- Demo program: backward.s
invokes 'mmap' system-call, addresses i/o ports, and employs '.rept' macro
- Demo program: timeoday.s
directly inputs the current time-of-day from the PC's Real-Time Clock chip
- Demo program: cmosdump.s
displays the current contents of all the Real-Time Clock chip's registers
- Demo program: activity.cpp
a tool for real-time monitoring of all processor interrupts and exceptions
- Kernel module: activity.c
(it creates the '/proc/activity' pseudo-file needed by our 'activity' monitor)
- Unfinished program: idnumber.s
is your starting point when answering question V on the Final Exam
- Problem solution: idnumber.s
shows one possible way of answering question V on the Final Exam
Announcements
- Project 1: Due Noon Monday, 27 February 2006
- Midterm Exam 1: Wednesday, 1 March 2006
- Project 2: Due Noon Monday, 27 March 2006
- Midterm Exam 2: Wednesday, 5 April 2006
- Project 3: Due Noon Wednesday, 26 April 2006
- FINAL EXAMINATION: Wednesday, 17 May 2006, 8am
Last updated on 06/07/2006