Refactor examples
This commit adds comments to previous examples, as well as add a new example demonstrating printing in Ripes
RENAME
examples/assembly/complexmult.s
examples/assembly/Complex multiplication
RENAME
examples/assembly/branchmany.s
examples/assembly/Conditional branching
+# This example demonstrates how to specify conditional branches
+# in the RISC-V assembly language.
+
.text
li a0,10
li a1,20

ADD
examples/assembly/Console printing
+# This example demonstrates how strings and integers may be
+# printed to the console of the Leros simulator
+
+.data
+str: .string "A string"
+newline: .string "\n"
+delimiter: .string ", "
+
+.text
+# ------ String printing ----------
+ la a1 str # Load the address of the string, placed in the static data segment
+ li a0 4 # Argument '4' for ecall instructs ecall to print to console
+ ecall
+
+ jal printNewline
+
+# ------ Integer printing ---------
+# Print numbers in the range [-10:10]
+ li a0 -10
+ li a1 10
+ li a2 1
+ jal loopPrint
+
+ jal printNewline
+
+# ------ ASCII character printing ---------
+# Print ASCII characters in the range [33:53]
+ li a0 33
+ li a1 53
+ li a2 2
+ jal loopPrint
+
+end:
+ # End program
+ li a0 10
+ ecall
+
+
+# ====== Helper routines ======
+printNewline:
+ la a1 newline
+ li a0 4
+ ecall
+ jalr x0 x1 0
+
+# --- LoopPrint ---
+# Loops in the range [a0;a1] and prints the loop invariant to console
+# a0: range start
+# a1: range stop
+# a2: print method (ecall ergument)
+loopPrint:
+ addi t0 a0 0
+ addi t1 a1 0
+loop:
+ # Print value in a1 as specified by argument a2
+ addi a1 t0 0
+ addi a0 a2 0
+ ecall
+ # Print a delimiter between the numbers
+ li a0 4
+ la a1 delimiter
+ ecall
+ # Increment
+ addi t0 t0 1
+ ble t0 t1 loop
+ jalr x0 x1 0

RENAME
examples/assembly/factorial.s
examples/assembly/Factorial function
+# This example shows an implementation of the mathematical
+# factorial function (! function).
+
.data
argument: .word 7 # Number to find the factorial value of
.text
main:
- lw a0, argument
- jal ra, fact
- jal zero, end
+ lw a0, argument # Load argument from static data
+ jal ra, fact # Jump-and-link to the 'fact' label
+ ecall 0 # Exit program
fact:
addi sp, sp, -16
@@ -29,4 +32,3 @@ nfact:
mul a0, a0, t1
jalr x0, x1, 0
-end:
\ No newline at end of file

RENAME
examples/assembly/loop.s
examples/assembly/Large program
+# This is an example written to demonstrate a medium-sized assembly
+# program. The program is not meaningful, but is instead intended
+# to test the simulator.
+
main:
addi sp,sp,-48
sw ra,44(sp)

RENAME
examples/assembly/shift.s
examples/assembly/Shifts
DELETE
examples/assembly/addlarge.s
- .text
- li a0,-2147483647
- li a1,2147483646
- add a2,a0,a1
- addi a0,x0,10
- ecall

DELETE
examples/assembly/addneg.s
- .text
- li a0,-32
- li a1,-64
- add a2,a0,a1
- addi a0,x0,10
- ecall

DELETE
examples/assembly/addpos.s
- .text
- li a0,5
- li a1,6
- add a2,a0,a1
- addi a0,x0,10
- ecall

DELETE
examples/assembly/branchcnt.s
- .text
-main:
- li a0,0
- li a1,10
-loop:
- addi a0,a0,1
- bne a0,a1,loop
- blt a0,a1,main
- bgt a0,a1,main
- mv a2,a0
- li a0,10
- ecall

MODIFY
examples/examples.qrc
examples/examples.qrc
<RCC>
<qresource prefix="/examples">
- <file>assembly/addlarge.s</file>
- <file>assembly/addneg.s</file>
- <file>assembly/addpos.s</file>
- <file>assembly/branchcnt.s</file>
- <file>assembly/branchmany.s</file>
- <file>assembly/complexmult.s</file>
- <file>assembly/factorial.s</file>
- <file>assembly/loop.s</file>
- <file>assembly/shift.s</file>
<file>binary/addlarge.bin</file>
<file>binary/addneg.bin</file>
<file>binary/addpos.bin</file>
<file>binary/loop.bin</file>
<file>binary/shift.bin</file>
<file>binary/storeloadnoforwarding.bin</file>
+ <file>assembly/Conditional branching</file>
+ <file>assembly/Complex multiplication</file>
+ <file>assembly/Factorial function</file>
+ <file>assembly/Large program</file>
+ <file>assembly/Shifts</file>
+ <file>assembly/Console printing</file>
</qresource>
</RCC>

Refactor examples

This commit adds comments to previous examples, as well as add a new example demonstrating printing in Ripes