CS 210: Assembly Language and Systems Programming (Spring 2007)
Mon-Wed 11:35pm-1:20pm (Room HRN-235)
Instructor:
Allan Cruse
cruse@usfca.edu
Phone: (415) 422-6562
Office: 212 Harney Science Center
Office Hours: (see my homepage)
Synopsis:
- 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,
"Assembly-Level Computer Organization:
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 2007
"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 (Fifth Edition)
Prentice-Hall, Inc. (2007), ISBN 0-13-238310-1
"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
The official
GNU Assembler manual (GAS)
Brennan's Guide to Inline Assembly
The Linux
Assembly HOWTO manual
Roger Jegerlehner's
Intel Assembler 80x86 Code Table
Jialong He's LINUX System Call Quick Reference
(.pdf)
Official IA-32 Programmer Reference Manuals, Intel Corporation
Documentation for the Linux Executable and Linkable Format (ELF) files:
elf.pdf
Notes on the rules for leap year
from Dr. Robert Alan Wolf (USF mathematics department)
Official datasheet for the
PC16550D Serial UART (.pdf format), National Semiconductor, Inc
Official Data Sheet for the
Dallas Semiconductor DS12887 Real-Time Clock and CMOS Memory
A typical
CMOS RAM Memory-map for PC/AT compatible machines (at www.bioscentral.com)
Online listing of the
standard UNIX signals (at CS Dept: Univ of Pittsburgh)
Online tutorial on
Introduction to UNIX signals programming
(at Little Unix Programmers Group)
Official Data Sheet for the
8254 Programmable Interval Timer/Counter"
(Intel Corporation)
Systems Software
- Utility program: ljpages.cpp
(a tool that submits your program source to a laser printer)
<-- modified 04/02/2007
- Utility program: iopl3.cpp
(a tool by Alex Fedosov that lets user programs do direct I/O)
- 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)
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 of using the stack to reverse the order of stored characters
- Syntax demo: address.s
showing the various ways you can specify the location for a memory-operand
- Useful subroutines: base10io.s
(for converting between a numerical value and a decimal digit-string)
- Demo program: manydots.s
an 'interactive' application that you 'link' with a separately-assembled file
- Demo program: showpid.s
illustrating the 'getpid' system-call and our number-to-string conversion
- Demo program: tryfork.s
it introduces two additional Linux system-calls, named 'fork' and 'waitpid'
- Demo program: dopushal.s
shows a 'table-lookup' technique that you can adapt for use with Project 1
- Exercise solution: dopushaq.s
shows how you can modify our 'dopushal.s' for Linux on a 64-bit platform
- Demo program: cmdargs.s
shows how an assembly language program can get command-line arguments
- Exercise solution: mynameis.s
shows a command-line argument being used in a simple example-program
- Demo program: execdemo.s
combines use of the Linux 'execve()' system-call with 'fork()' and 'waitpid()'
- Demo program: secs2day.cpp
expresses an algorithm for computing today's date in a high-level language
- Demo program: datetest.cpp
showing how 'fork()' and 'execve()' could assist in the testing of an algorithm
- Exam-question prototype: iseven.cpp
shows what data-elements and algorithm-steps a solution would need
- Exam-question solution: iseven.s
showing one possible way of answering the Question V on Midterm Exam I
- Demo program: xmas.s
employs some algorithms that use the Pentium's 'mul' and 'div' instructions
- Demo program: xmastest.s
provides the skeleton for a program that can automate testing of 'xmas'
- Some test-data: easter.doc for project #2
- Debugging tool: db.tar.gz
it lets you single-step through your Linux assembly language programs
- Demo function: gcd.s
an implementation in assembly language of the ancient Euclidean Algorithm
- Demo programs: gcdcalc.c
and gcdcalc.cpp
examples that illustrate "mixed-language" programming
- Demo function: fact.s
shows a 'recursive' function that has been written using assembly language
-- revised on 04/15/2008
- Demo program: tryrecur.cpp
showing how a C++ program could call the external function in 'fact.s'
- Demo program: triangle.cpp
this is the C++ program that you will need to modify for your Project #3
- In-class exercise: exponent.cpp
along with one possible solution using assembly language:
expo.s
- Demo program: out2file.s
shows how to invoke the basic system-calls that are needed to create a file
- Demo program: filesize.s
showing how to use the 'lseek' system-call to obtain the size of a given file
- Demo program: brkdemo.s
showing how to use the 'brk' system-call to allocate memory dynamically
- Exercise solution: bigbreak.s
shows one way of solving the in-class exercise (on 'maximum' brk-value)
- Demo program: mywhoami.s
shows the use of some string-instructions (cmpsb, scasb, movsb, stosb)
- Demo program: testuart.s
uses 'loopback' mode to illustrate programming of the serial UART device
- Exercise solution: uartecho.s
shows one possible solution to the in-class UART programming exercise
- Demo program: timeoday.s
directly inputs the current time-of-day from the PC's Real-Time Clock chip
- Exam-question solution: tomorrow.s
showing one possible answer for Question V on Midterm Exam II
- Exam-question solution: product.s
showing one possible way to answer Question IV on Midterm Exam II
- Demo program: prodtest.cpp
provides a convenient 'testbed' for executing the function in 'product.s'
- Demo program: sigvtrap.s
shows how you could use a signal-handler to help you find program 'bugs'
- Demo program: cpuspeed.s
this is a 'boot-time' program, designed to measure the CPU's speed
- Linker script: ldscript
needed when linking the 'cpuspeed.s' demo-program (for non-Linux format)
- Demo program: showreal.s
introduces students to the use of some x86 floating-point instructions
- 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: zeta2.s
uses floating-point instructions to compute a series-approximation for zeta(2)
- 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
- 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
- Exam-question solution: sqroots.s
showing one possible answer for Question V on the Final Exam
Announcements
- Enrolled students may join the class mailing-list
here
- project1: Due Noon Friday, 23 February 2007
- Midterm Exam 1: Monday, February 26
- project2: Due Noon Friday, 9 March 2007
- project3: Due Noon Friday, 30 March 2007
- Midterm Exam 2: Wednesday, April 11
- project4: Due Noon Friday, 13 April 2007
- project5: Due 10am Wednesday, 2 May 2007
- FINAL EXAMINATION: Noon, Wednesday, 16 May 2007
Last updated on 04/15/2008