Fix issue in example
ecall does not take arguments.
Furthermore, added some printing to the Factorial example for a bit nicer output.
MODIFY
examples/assembly/Factorial function
examples/assembly/Factorial function
.data
argument: .word 7 # Number to find the factorial value of
+str1: .string "Factorial value of "
+str2: .string " is "
.text
main:
lw a0, argument # Load argument from static data
jal ra, fact # Jump-and-link to the 'fact' label
- ecall 0 # Exit program
+
+ # Print the result to console
+ mv a1, a0
+ lw a0, argument
+ jal ra, printResult
+
+ # Exit program
+ li a0, 10
+ ecall
fact:
addi sp, sp, -16
@@ -31,4 +41,30 @@ nfact:
addi sp, sp, 16
mul a0, a0, t1
- jalr x0, x1, 0
+ ret
+
+
+# expects:
+# a0: Value which factorial number was computed from
+# a1: Factorial result
+printResult:
+ mv t0, a0
+ mv t1, a1
+
+ la a1, str1
+ li a0, 4
+ ecall
+
+ mv a1, t0
+ li a0, 1
+ ecall
+
+ la a1, str2
+ li a0, 4
+ ecall
+
+ mv a1, t1
+ li a0, 1
+ ecall
+
+ ret

Fix issue in example

ecall does not take arguments.
Furthermore, added some printing to the Factorial example for a bit nicer output.