Open andrewt0301 opened 2 years ago
Group 201, variant 12. Taken from here:
f(x) = 4 if x < 5
f(x) = 7 * x + 2 if x >= 5
f(x) = 2 * x**8 - 2 * x**4 + 3 * x**2 + 7 * x if x == 6
f(x) = -10**x + 9 if x > 9
#f(x) = 4 if x < 5
fx:
li a7, 5
ecall
mv s1, a0
addi t0, t0, 5
blt s1, t0, f_1
f_1:
addi t1, t1, 4
mv s1, t1
mv a0, s1
li a7, 1
ecall
#f(x) = 7 * x + 2 if x >= 5
fx:
li a7, 5
ecall
mv s1, a0
addi t0, t0, 5
bge s1, t0, f_2
f_2:
addi t1, t1, 2
addi t2, t2, 7
mul s1, s1, t2
add s1, s1, t1
mv a0, s1
li a7, 1
ecall
f(x)
function that would handle all cases. Instead, there are two separate programs that do not compile together.f(x) = 4 if x < 5
- incorrect, always prints 4 (even when x is 10)f(x) = 7 * x + 2 if x >= 5
- partially icorrect, calculates result even if x < 5 (e.g. {x=10, result=72} - correct, {x=1, result=9} - incorrect)f(x) = 2 * x**8 - 2 * x**4 + 3 * x**2 + 7 * x if x == 6
- missingf(x) = -10**x + 9 if x > 9
- missing
Notes on Final Test Programming Task
Task
The programming task as specified here:
Write a RISC-V assembly program that inputs integer value x (assumed non-negative) and calculates the value of the f(x) mathematical function according to the specified equations. f(x) must be implemented as a function and must comply with RISC-V calling conventions.
The implemented function must use callee-saved registers (s0, s1, etc.) to store intermediate results of calculations. These registers must be saved to the stack and restored when the function returns.
Variant
Group 202, variant 7. Taken from here:
This task means to create a RISC-V assembly program that does the same as this Python program:
Expected results:
Solution
Notes
f(x)
function: -2f(x) = 6 * x**5 + 4 * x**3 - 5 * x**2 + 7 * x if x < 5
- does not work, -2f(x) = 4 if x >= 5
- OKf(x) = 7**x + -2 if x == 6
- wrong,250
vs.117647
, -2f(x) = -1 * x + 10 if x > 9
- OKResult
10 - 2 - 1 - 2 - 2 = 3