1
CS 5375: Computer Systems Organization and Architecture
Fall 2024
Instructor: Dr. Morshed, Associate Professor, Computer Science, Texas Tech University
Assignment 4: Assembly program for functions
Note: You must show your work of intermediate steps, as appropriate, to receive full marks.
Problem 1 (100%)
Convert the follow C code to RISC V assembly code.
int fun (int x, int y) {
res = abs (x, y) – abs (y, x);
return res;
}
int abs (int x, int y) {
if (x >= y)
return x – y;
else
return y – x;
}
Assume x, y, and res are mapped to a0, a1, and s0. Return value must use a0. For all other purposes,
use temporary registers.