Skip to content

CS 315-01 Lecture/Lab — Meeting Summary (Fall 2025)

  • Date: September 24, 2025
  • Time: 05:04 PM Pacific Time (US and Canada)
  • Meeting ID: 886 4953 2573

Quick Recap

The session transitioned from assembly language to machine code. The instructor (Greg) outlined progress in learning assembly, plans to deepen RISC-V instruction set knowledge, and the introduction of a RISC-V machine code emulator. He reviewed the interactive grading process for Project 3, analyzed a subtle bug in a string-reversal function related to null terminators, and previewed upcoming topics: bitwise operations, binary arithmetic, the structure of 32-bit values, and emulator-oriented assignments.

Next Steps

  • Memorize the truth tables for bitwise operators for the remainder of the semester.
  • Prepare for Project 4 (due in a few weeks).
  • Learn the RISC-V machine code format for the upcoming emulator project.
  • Practice bit manipulation in both C and RISC-V.
  • Students who graded with Greg for Project 3 will grade with TAs for Project 4 to ensure broader instructor interaction.

Detailed Summary

RISC-V Machine Code Emulator

  • The course is moving from assembly to machine code now that students can write moderate-sized assembly functions.
  • The class will deepen understanding of the RISC-V instruction set, especially bitwise operations and bit manipulation.
  • A new learning approach: build a RISC-V machine code emulator in C that emulates binary object files, reinforcing knowledge of machine code formats and instruction decoding.

Interactive Grading Process Overview

  • Project 3 used interactive grading to promote understanding and accountability.
  • TAs provide feedback; Greg reviews to ensure consistency and fairness.
  • Use of AI tools (e.g., ChatGPT) is permitted, but students must:
  • Understand their code thoroughly.
  • Explain decisions and implementations during grading.
  • For Project 4, a different set of students will grade with Greg to ensure everyone gets instructor interaction.

String Reversal Code Mystery

  • A C string-reversal function contained a subtle error but appeared to work due to how it handled the source string’s null terminator.
  • The function skipped the source string’s null terminator and never encountered it during execution.
  • The instructor plans to diagram and further analyze the null terminator’s role to explain why the bug went unnoticed in prior semesters.

Reverse String Bug Fix Discussion

  • The bug stemmed from incorrectly using the null terminator of a previous string in memory.
  • Correct fix: check whether the source index becomes less than zero to detect the end of the string, rather than relying on memory state from prior strings.
  • Students should understand this bug and fix pattern; it may appear on an exam.

RISC-V Emulator Development Overview

  • The course has covered data representation and is now focusing on RISC-V machine code.
  • Goal: implement a RISC-V emulator in C to execute binary code, then run equivalent code on actual RISC-V machines and student-designed processors.
  • Mastery of bitwise operations in both C and RISC-V is essential for compiling and decoding instructions.

Bitwise Operators in C Programming

  • Bitwise vs. relational operators:
  • Bitwise operators manipulate individual bits.
  • Relational/logical operators control conditional flow.
  • Refresher topics:
  • Binary-to-decimal conversion.
  • 32-bit values: byte organization and bit positions.
  • Core operators discussed (applied positionally to each bit):
  • AND (&)
  • OR (|)
  • XOR (^)
  • NOT/complement (~)
  • Left shift (<<)
  • Right shift (>>)
  • Truth tables and positional application were emphasized.

Binary Operations in C

  • Inclusive OR, exclusive OR, and NOT were demonstrated with binary examples.
  • Students should become fluent in applying these operators to variables in C and reasoning about the resulting bit patterns.

Bit Shifting Basics

  • Logical shifts:
  • Left shift inserts zeros on the right; multiplies unsigned values by powers of two.
  • Right shift (logical) inserts zeros on the left.
  • Arithmetic right shift preserves the sign by filling with ones for negative values (implementation-defined for signed types in C; conceptually preserves sign).
  • Hardware context briefly introduced (barrel shifters and digital logic).

Binary Arithmetic Operations Overview

  • Two’s complement:
  • To negate: invert bits and add one.
  • Understanding sign, magnitude, and overflow is critical.
  • Shift distinctions:
  • Left vs. right shifts and their effects on sign and magnitude.
  • Arithmetic right shift vs. logical right shift behavior.
  • Multiple examples were converted between binary and decimal to reinforce understanding.

Bitwise Operations and Emulator Basics

  • Example C code demonstrated bitwise shifts and masks.
  • Emulators were defined as software that simulates hardware functionality.
  • Next lecture: decoding machine instructions with bitwise operators and beginning the emulator.
  • Lab: related assignment due Tuesday night of the following week (a typo in the lab handout will be corrected in Lab 4).

Key Emphases

  • Memorize and use truth tables for AND, OR, XOR, and NOT.
  • Be precise with bit positions, masks, and shifts when decoding instructions.
  • Understand two’s complement and arithmetic vs. logical shifts.
  • Be prepared to explain code and reasoning during interactive grading.
  • Expect emulator-focused assignments and instruction decoding exercises shortly.