Introduction to CS 301

CS 301 Lecture, Dr. Lawlor, 2005/09/02

Pass out course syllabus.  Hit the high points.

The key question to answer at the start of this class is this:

Why would anybody ever want to learn assembly language?

I.e., why not just use a compiler?
  1. Assembly is a CS degree requirement. An honest answer! But this only begs the question: "Why is it a degree requirement?".
  2. Compiler generation. You need to know assembly to *write* a compiler, or at least a compiler that generates code that will run on the real machine.
  3. Help debugging. Being able to understand assembly lets you see what's really going on when something goes wrong, which at least will help you find the problem, andcan sometimes help you fix it.
  4. Help optimize code, both by directly writing assembly, and by understanding what the machine does underneath.  Almost nobody writes lots of code in assembly anymore, but anybody--using any language--can write faster code if they know what the machine has to do in order to run it.
  5. Run on tiny machines.  How can you run your code in (I kid you not) 128 bytes of RAM? Silly answer: very carefully!  A compiler may use more time and space than you have on the machine. Tiny machines, like the PIC microcontroller, are used inside cell phones, calculators, microwaves, toasters, watches, toys, etc.
  6. To do things other languages won't let you you do, like access special instructions.  Often this sort of assembly can be turned into small macros or inline functions, and then called from other languages like C.  Examples of these "assembly wrapper" headers include Intel's <mmintrin.h> header.
  7. To work around problems in existing *compiled* code, when you don't even have source code, you've got to mess with the machine code, often inside a hex editor.  This is a good argument for using open-source code instead of proprietary binary code, but there's a lot of proprietary code out there being used, and there are times when you really have to fix a bug now.
  8. To enable bizarre new functionality by generating code at runtime (e.g., Java Just-In-Time (JIT) compilation, ARB_fragment_program).