CS 241 - Foundations of Sequential Programs
Instructor: Kevin Lanctot
Location: RCH 309
Time: Tuesdays and Thursdays 8:30am - 9:50am
Term: Winter 2017

January 3, 2017 - Lecture 1

Course Overview

Purpose: To understand what happens when you compile and run a program

High-level languages (CS 241) -> Machine code (CS 251)

Major topics:

  • Machine architecture and assembly language
  • Assemblers, linkers, loaders
  • Regualr languages and scanning
  • Context-free languages and parsing
  • Semantic analysis and code generation
  • Runtime organization and data layout

Marking Scheme

  • Assignments (25%, 10 assignments, due Fridays at 5pm)
    • Public and release cases
    • 3 release tokens which takes 12 hours to regenerate
  • Midterm exam (25%, 4:30pm, Wednesday, March 1, 2017)
  • Final exam (50%)
  • Computer Organization and Design by Patterson and Hennessy
  • BoCD (Basics of Compiler Design) by Mogensen

Lectures 1, 2

Key Ideas

  • Binary, decimal, two’s complement
  • Addition and subtraction

January 10, 2017 - Lecture 3

  • MIPS (binary) reference
    • For each instruction, there is a name, assembly language mnemonic, binary, and MIPS meaning
PC <- 0
while (1) {
  fetch word from RAM at address in PC (RAM[PC]) into IR
  PC <- PC + 4
  execute instruction in IR
}
  • MIPS Assembly Language (CS241 edition) Reference
    • MIPS assembly language programs are text files
    • Each line is either NULL or contains an instruction
    • Each line has:
      • 0 or more labels (placeholders, used by goto instructions)
      • 0 or 1 instructions
      • Comments (optional) started by a colon
    • Example:
      jr $3
      jr $3 ;helloWorld
      
    • Example:
      (blank line) NULL LINE
      foo: bar: diff: beq $1, $1, 1
      boo:
      ; comment (this is a null line)
      bah: ; comment after a label
      
    • Each non-null line contains an instruction
    • Each instruction consists of an mnemonic and operands
      • Format: mnemonic [operands]
      • Possible mnemonics: .word, add, sub, mul, jr, jalr, etc.
      • Possible operands: decimal numbers, hex, ints
        • Up to 232-1 down to -231