Fundamentals of Programming and Computer Architecture Notes

Course Objectives and Learning Outcomes

  • Identify the respective roles of hardware and software in a computing system.

  • Explain the form and function of computer programming languages.

  • Master basic software creation and execution using the Python programming language.

Modern Computer Definition and System Fundamentals

  • Universal Machine Concept:

    • A modern computer is defined as a machine that stores and manipulates information under the control of a changeable program.

    • The two foundational elements of a computer system are:

      • Information Manipulation: Computers are electronic devices configured explicitly to store, retrieve, and process data.

      • Programmability: Operation occurs entirely under the control of a changeable program.

  • Computer Programs:

    • A computer program is a detailed, step-by-step set of instructions that dictates exact operations to the computer hardware.

    • Modifying the software program changes the tasks and behavior of the machine without necessitating any alteration to the underlying physical hardware.

  • Role and Impact of Software:

    • Software (programs) rules hardware (the physical machine).

    • The creative process of authoring software programs is termed programming.

    • Understanding computer programming provides essential insight into the inherent capabilities, computational strengths, and structural limitations of computers.

    • Learning programming develops computational thinking and complex problem-solving skills by training developers to analyze intricate systems through decomposition into simpler interacting subsystems.

Hardware Architecture and Components

  • Input Devices:

    • Input devices pass external raw data and control signals into the computing system.

    • Examples include keyboards, computer mice, digital cameras, graphics tablets, optical scanners, webcams, and joysticks.

  • Output Devices:

    • Output devices display or transmit processed information back to human users or other external systems.

    • Examples include computer monitors, printers, and audio speakers.

  • Central Processing Unit (CPU):

    • The Central Processing Unit serves as the primary computational "brain" of the computer.

    • Performs basic mathematical operations (such as simple arithmetic calculations) and logical operations (such as testing whether two numerical values are equal).

  • Memory Hierarchies:

    • Main Memory (RAM - Random Access Memory):

      • High-speed memory directly accessible by the CPU to read and write temporary instructions and data.

      • RAM is volatile storage, meaning all stored contents are lost when system power is disconnected or interrupted.

    • Secondary Storage:

      • Provides persistent, non-volatile storage for permanent data and software files.

      • Includes magnetic storage media (hard drives, floppy disks) and optical storage media (CDs, DVDs).

Functional View of Computer
  • The Fetch-Execute Cycle:

    • The fundamental operational loop of the CPU consisting of four continuous stages:

      1. Fetch: The next scheduled instruction is retrieved directly from main memory (RAM).

      2. Decode: The Control Unit decodes the retrieved instruction byte sequence to determine the required operations.

      3. Execute: The Arithmetic/Logic Unit (ALU) or control unit executes the decoded command.

      4. Store: Output results are written back to main memory as required, and the CPU continuously repeats the sequence.

Fetch-Execute Cycle

System Software and Programming Languages

  • System Software Classification:

    • System software manages and coordinates basic hardware operations and computer resources.

    • Divided into three primary sub-categories:

      1. Operating Systems: Manage system hardware allocation, process execution, and file management.

      2. Utility Programs: Perform specialized system maintenance, diagnostics, and optimization routines.

      3. Software Development Tools: Provide environments, compilers, and debuggers for writing and running code.

  • Characteristics of Programming Languages:

    • Natural human languages possess inherent ambiguity and lack the precision required to communicate complex algorithms to computing hardware.

    • Programming languages offer unambiguous, mathematically precise rules for algorithm representation.

    • Programmers refer to written software programs as computer code, and the process of algorithm construction is called coding.

  • Levels of Abstraction:

    • High-Level Computer Languages:

      • Designed for human readability and conceptual clarity, abstracting away from machine hardware details (e.g., c=a+bc = a + b).

      • Examples include Python, C, Java, and Pascal.

    • Low-Level Computer Languages:

      • Machine language consists of binary instruction sequences (such as 10100001, 10111000, 10011110) that physical electronic microprocessors process directly.

      • Assembly language provides symbolic representation corresponding directly to low-level machine instructions.

Translation Mechanisms: Compilation vs. Interpretation

  • Compilers:

    • A compiler translates an entire high-level program into low-level machine code prior to execution.

    • Generates a standalone machine language program executable directly by the CPU at any time without needing the compiler or original source file present.

Compile and Execute Process
  • Interpreters:

    • An interpreter reads, analyzes, and translates a high-level source program line by line or instruction by instruction, immediately executing each translated line on the CPU.

    • The translation process repeats for every individual instruction throughout the execution loop.

Interpreter Process
  • Comparative Execution Characteristics:

    • Execution Speed: Compiled programs generally run significantly faster because translation happens once beforehand, whereas interpreted programs translate code continuously at runtime.

    • Portability & Interactivity: Interpreted environments support flexible, interactive development environments that enable real-time code testing and rapid iteration.

    • Dependencies: Running compiled executables requires no source code or translation tools; running interpreted software requires both source files and the interpreter environment on the target machine.

  • Syntax vs. Semantics:

    • Syntax: The exact form, structure, and grammar rules required to construct valid statements in a programming language.

    • Semantics: The precise logical meaning and functional behavior associated with syntactic structures in a programming language.

Python Applications and Development Environment

  • Key Application Domains:

    • Web Development

    • Game Development

    • Computer Vision

    • Machine Learning

    • Graphical User Interface (GUI) Development

    • Robotics (e.g., embedded development on Raspberry Pi)

    • Data Analysis

  • Anaconda Distribution Ecosystem:

    • Anaconda distribution offers an integrated platform for Python environment management and data science.

    • Anaconda Navigator includes graphical launchers for developer tools:

      • PyCharm (Integrated Development Environment tailored for Python and machine learning)

      • JupyterLab and Jupyter Notebook (Web-based interactive computing environments)

      • Spyder (Scientific Python Development Environment)

      • VS Code (Streamlined code editor supporting debugging and version control)

      • Orange 3 (Data visualization and mining component framework)

  • Jupyter Notebook Interface Operations:

    • Creating Notebook Files (.ipynb): Select New -> Python 3 (ipykernel) from the environment file manager.

    • Cell Control Toolbar Features:

      • Add Cell (+ icon): Inserts a new execution cell.

      • Remove Cell (Cut/Scissors icon): Deletes selected cells.

      • Execute Code (Run icon): Submits active cell code to the underlying Python kernel.

      • Restart Kernel (Restart icon): Resets system state and memory bindings.

Core Python Programming Constructs

  • Output and Expressions:

    • Printing String Literals: print("Hello World") outputs exact string content: Hello World.

    • Arithmetic Evaluation: print(2+3) evaluates mathematical expression and outputs: 5.

    • Literal String Non-Evaluation: print("2+3") prints string literally without arithmetic processing: 2+3.

  • Functions and Parameters:

    • Functions allow combining multiple program statements into reusable named blocks.

    • Defined using the def keyword followed by the function name, parameter list, and a colon :.

    • Code blocks belonging to a function are grouped strictly via indentation.

    • Function Definition Example: python def hello(): print("Hello") print("Computers are fun!")         

    • Defining a function stores its block in memory without immediate execution; calling or invoking the function requires referencing its name with parentheses (e.g., hello()).

    • Parameters pass variable inputs inside parentheses (), enabling customized output behavior: python def greet(person): print("Hello", person) print("Computers are fun!")         

    • Calling greet("Mike") produces: text Hello Mike Computers are fun!         

  • Modules and Architecture:

    • Definitions entered directly inside interactive prompts are temporary and disappear once the session terminates.

    • Permanent code storage requires saving definitions in text files with .py extensions, known as modules.

    • Structural Hierarchy: Modules contain Classes, and Classes contain Functions.

Analysis of Code Structure: The Chaos Program Example

  • Complete Python Program (chaos.py): ```python

    File: chaos.py

    A simple program illustrating chaotic behavior

    def main(): print("This program illustrates a chaotic function") x = eval(input("Enter a number between 0 and 1: ")) for i in range(10): x = 3.9 * x * (1 - x) print(x)

    main()     ```

  • Structural Elements Breakdown:

    • Comments:

      • Lines beginning with # are comments ignored by the Python interpreter.

      • Comments serve exclusively as human-readable documentation.

    • Variables and Assignment:

      • xx is a variable used to store and reference a value in memory.

      • eval(input("...")) displays the text prompt to the user, accepts keyboard input, evaluates the input into a numeric representation, and assigns it to variable xx.

    • For Loops and Iteration:

      • for i in range(10): defines a loop structure that instructs Python to repeat a sequence 1010 times.

    • Loop Body and Indentation:

      • The indented block beneath the for statement forms the body of the loop.

      • Contains the logistic map formula x=3.9×x×(1−x)x = 3.9 \times x \times (1 - x) followed by print(x).

      • The loop body executes 1010 consecutive times, modifying xx in place and displaying its updated value during each iteration.

    • Chaotic Function Output Trace:

      • Inputting an initial seed value between 00 and 11 yields a deterministic yet non-repeating sequence.

      • For initial input 0.20.2, the produced output sequence is:

        • 0.6240000000000001

        • 0.9150335999999998

        • 0.30321373239705673

        • 0.8239731430433209

        • 0.5656614700878645

        • 0.9581854282490118

        • 0.1562578420270518

        • 0.5141811824451928

        • 0.9742156868513789

        • 0.09796598114189214

Recommended Literature and Academic References

  • Primary Reference:

    • Gaddis, T. (2018). Starting out with Python (4th ed.). Essex, England: Pearson Education Limited.

  • Supplementary References:

    • Zelle, J. (2016). Python programming: An Introduction to Computer Science (3rd ed.). Washington, USA: Franklin, Beedle & Associates Inc.

    • Punch, W., & Enbody, R. (2016). The Practice of Computing using Python (3rd ed.). Upper Saddle River, NJ: Pearson Education.