Department of Computer Science |
University of San Francisco |
---|

Computer Architecture

Code Examples

- Arithmetic
- Branching
- C program that prints whether an input value is negative
- MIPS program that prints whether an input value is negative
- MIPS program that reads in two ints x and y and prints their difference. If y is negative, it prints x-y. Other wise it prints y-x.

- Looping
- C program that finds the sum of the first n positive integers
- MIPS program that finds the sum of the first n positive integers
- MIPS program that finds the
sum of the first n positive integers. This version
replaces the
`bgt`with core instructions. - C program that finds the sum of the elements in a user input list of nonnegative integers. Input is terminated by a negative value.
- MIPS program that finds the sum of the elements in a user input list of nonnegative integers. Input is terminated by a negative value.

- I/O
- A very simple C program that uses functions to read in an int and then print out the int.
- A MIPS program that uses functions to read in an int and then print it out.
- A MIPS program that uses functions to read in a list of ints and then print it out.

- Fibonacci Numbers
- Sorting
- C implementation of selection sort
- MIPS implementation of selection sort
- C implementation of selection sort. This version allocates storage for the list on the heap.
- MIPS implementation of selection sort This version allocates storage for the list on the heap.
- MIPS implementation of selection sort This version "dynamically" allocates storage for the list on the stack.
- C implementation of count sort
- MIPS implementation of count sort

- Binary representation
- Parallelism
- A C program that attempts to implement a spinlock. This has a serious bug.
- x86 functions that implement a spinlock. These can be used in the preceding C program to correctly implement a spinlock.
- MIPS program with two different implementations of a lock function

- Arithmetic Algorithms
- Decimal addition
- Binary addition
- Decimal subtraction
- Binary subtraction
- Decimal multiplication
- Binary multiplication
- Binary multiplication Binary numbers are stored as computer words

- MIPS multiply
- Signed multiplication
. The high order 32 bits are stored in
`hi`. The low order 32 bits are stored in`lo`. - Unsigned multiplication
with overflow. Use registers
`hi`and`lo`. - Multiplication with no overflow

- Signed multiplication
. The high order 32 bits are stored in

Peter Pacheco 2016-04-10