Overview
This lecture covered fundamental MIPS assembly programming concepts, including memory structure, system calls, registers, writing and debugging simple programs, converting C to "simplified C," using branching, and implementing loops.
Course and Lab Announcements
- Week 2 lab sessions are held online via Blackboard Collaborate, focusing on C revision and recursion.
- No ticketing system for labs unless overcrowded; support for lab week 1 questions is also available.
Memory & Program Structure Recap
- Programs are loaded into RAM, divided into code (text), data, heap, and stack segments.
- Registers are fast CPU memory locations, each with specific purposes and preferred symbolic names.
- Instruction set architectures (e.g., x86, MIPS, ARM) define available machine instructions.
MIPS Assembly Programming Basics
- Most computations occur between registers, not directly with memory.
- Use
li for loading immediate values into registers (pseudo-instruction).
add operates on register values; addi allows adding immediate values.
- Use
mul for multiplication, sub for subtraction; check MIPS documentation for instruction syntax.
System Calls & Input/Output
- System calls are requests for the OS to perform privileged tasks (I/O).
- MIPS system calls require placing the syscall number in
v0 and arguments in a0; results often returned in v0.
- Example syscalls: print integer (
v0=1), read integer (v0=5), print character/string (v0=11/4).
- Use labels and the
.data section for strings; end strings with a null terminator (.asciiz).
Code Structure & Style
- Use symbolic constants for syscall numbers for clarity.
- Prefer readable, commented code over micro-optimizations.
- Inline equivalent C code as comments.
- Indent code as specified (eight-wide tabs), avoid indenting labels.
Branches, Conditions, and Simplified C
- Branch instructions: conditional (
beq, bne, etc.) and unconditional (j).
- Simplified C replaces curly brackets and complex expressions with
goto and labels, making one-to-one translation to assembly easier.
- Avoid
goto in standard C, but it's useful for assembly translation.
- De Morgan's Law helps simplify logical expressions with AND/OR.
- Structure if/else and loop constructs with labels and conditional branches for assembly.
Loop Translation
- Convert for-loops to while-loops, then to
if+goto style for MIPS translation.
- Label all major loop steps: init, condition, body, step, and end.
- Always ensure loop condition and proper branching to avoid infinite loops.
Key Terms & Definitions
- Register — Small, fast memory storage within the CPU for intermediate values.
- System Call — Request from a program for the OS to perform a service (e.g., I/O).
- Pseudo-instruction — An assembly command translated to one or more real machine instructions.
- .data section — Part of the program storing global/static data and strings.
- .asciiz — Directive to store a null-terminated ASCII string.
- Label — Named marker in code for jumps/branches; ends with a colon.
- Simplified C — Version of C code with minimal syntax, making translation to assembly easier.
- Branch Instruction — Assembly command altering control flow based on a condition (e.g.,
beq, bne).
Action Items / Next Steps
- Review MIPS system calls and register usage documentation (available on course website).
- Practice translating loops and conditionals from C to simplified C and then to MIPS assembly.
- Complete lab exercises on recursion, C revision, and debugging MIPS programs.
- Prepare questions for the next session; unresolved lecture material will be covered next time.