CMPUT 229 - Computer Organization and Architecture I

Examples of Code Patterns and Structure in RISC-V

Examples of Code Patterns and Structure in RISC-V

This resource provides patterns for RISC-V assembly beginners along with explanations that allow the combination of different structures that can be used to write useful programs in RISC-V assembly.

These files are meant to be suggestions or aids, not rules and laws. This is not the only way to solve the programming problems illustrated but it can help you get started.


Contents

The links in this overview take you to the appropriate sections; feel free to skip to what you need now.

  1. Elements and structure of a RISC-V file assembly program.

  2. Function structure.

    • Basic Subroutines: Introduces basic leaf functions.
    • Argument and Return Values: Covers a simple way of passing args between functions.
      Note that this example ignores register calling conventions, which will be expected later in the course.
    • Main Function: Introduces the main function.
  3. Conditional statements.

    • If: Introduces a basic if conditional.
    • If/Else: Introduces an if with an unconditional else block.
    • If/Elif/Else: Introduces an if, with conditional elif blocks and finally an unconditional else block.
  4. Creating loops.

  5. RISC-V Dot Graph Generator: A Call-Graph Display for RISC-V Assembly


Acknowledgement