CS 101

Software

Plan for Today

figure

Reminder from last time


 

What happens when we press run?

Architecture: Machine Code

Architecture refers to the instructions sent by software that hardware can understand.

  • Reminder: CPU runs code instructions
  • Each line of machine code is one operation
  • Javascript is higher-level language
    • Have to translate Javascript to machine code
  • CPU runs the machine code (binary)
  • Machine-specific

Architecture: Assembly

mov    %esp,%ebp
sub    $0x28,%esp
mov    0x804d300,%eax
add    $0x1,%eax
mov    %eax,0x804d300
mov    0x804d300,%eax
cmp    0x8(%ebp),%eax
  • Assembly is converted to machine code
  • %esp, %ebp, etc. are in temporary storage

Programs and Applications

  • Millions of lines of machine code per program
    • Firefox.exe is about 20 million machine code instructions
  • All the machine code is in the .exe (Windows) or .app (Mac) file

The Operating System

figure
  • Name types of operating systems?
  • Starts running when the computer "boots up"
  • Manager/supervisor
    • Starting/stopping programs
    • Manages RAM, persistent storage, and other shared resources between programs
  • Can run multiple programs at once ("sandboxing")
  • Allows a computer to change over time (updates)
  • Other responsibilities:
    • File system
    • Manages windows
    • Some basic programs

OS: Starting a Program

  • Load the program file from the file system (persistent storage)
  • Each program gets its own RAM
    • Program's machine code
    • Data the program manipulates (like file being edited)
  • Copy machine code from persistent storage to RAM

OS: Running programs

  • CPU "fetch/execute cycle"
    • Fetch one instruction
    • Execute (run) that instruction
    • Repeat
  • Machine code is loaded into RAM
  • CPU begins at the top
    • Instructions like "return to step 5" keep the program running
figure

OS: Program runs and exits normally

  • Operating system starts and stops programs
  • Each program has its own separate area in RAM: its instructions + data
  • CPU "round robin"
  • Persistent storage is organized as a file system, programs can read and write data here
  • User quits the program
  • Operating system reclaims shared resources

OS: Abnormal Exit

  • Program "not responding"
  • The operating system stops running that program - involuntary vs. normal-exit
  • The operating system reclaims the program's area of RAM
  • Use Activity Monitor (Mac)/Task Manager (Windows)

OS: Running Out Of Memory

  • A program requests more RAM from the operating system
    e.g. to hold an image, but there's not enough RAM available
  • The operating system refuses the request, the program gives an error message

OS: Memory Access Error

  • A program tries to access the memory of another program
    • Maybe because of a bug (common)
    • Maybe on purpose because it is malware
  • The operating system blocks the access (ideally)
  • Maybe kills the offending program too

OS: Reboot

  • Why does this fix anything?
  • Sometimes some operating-system managed bytes in RAM is not quite right
    • a bug in the operating system, or perhaps a hardware error
  • A reboot wipes all the data from RAM
  • Starts up the operating system fresh
  • This should never be necessary

Programming Languages

  • Another layer of abstraction!
  • Closer to how humans think (vs. machine code)
  • What programming languages have you heard of?
  • High-level vs. low-level

Programming Languages
to Machine Code

  • Compiled
    • Source code vs. object code
    • Compiled once, run many times
    • Slow to compile
    • Java, C, C++
  • Interpreted
    • Machine code instructions generated on the fly
    • Slower to run, but no compile step!
    • Python, JavaScript

Programming Languages: Source Code

  • Source code is editable
  • .exe/.app files are just machine code
  • Can't change a program without the source code!
  • License is to use the software, not change it

Open Source in Theory

  • Idea: give everyone the source code!
  • No more licenses (free to use)
  • Examples:
    • Programming languages
    • Browsers
    • Operating Systems
    • Compilers
  • Championed by Richard Stallman
    • Free Software Foundation
    • Emacs, compiler, and more
    • Led to Linux

Open Source in Practice

  • Give out source code (Github)
  • Users have a right to modify the source code
  • Users are incentivized to contribute back with changes
  • Results:
    • Not a competitive advantage
    • Higher quality
    • Better use of resources

Conclusion

figure