Change ecall to funct->a7, arg->a0-a6
MODIFY
examples/assembly/Complex multiplication
examples/assembly/Complex multiplication
@@ -16,17 +16,17 @@ lw a3 , dd
jal complexMul
nop
mv t0, a1 #Move imaginary value to t0
-mv a1, a0 #Move real value to a1
+mv a0, a0 #Move real value to a1
-li a0, 1 #Set ecall to print integer
+li a7, 1 #Set ecall to print integer
ecall #Print integer
-la a1, str
-li a0, 4
+la a0, str
+li a7, 4
ecall
-mv a1, t0 #Move imaginary value to a1
-li a0, 1
+mv a0, t0 #Move imaginary value to a1
+li a7, 1
ecall #Print integer
j end # Jump to end of program

MODIFY
examples/assembly/Conditional branching
examples/assembly/Conditional branching
@@ -21,5 +21,5 @@ e:
li a1,2
f:
mv a2,a0
- li a0,10
+ li a7,10
ecall

MODIFY
examples/assembly/Console printing
examples/assembly/Console printing
@@ -8,8 +8,8 @@ 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
+ la a0 str # Load the address of the string, placed in the static data segment
+ li a7 4 # Argument '4' for ecall instructs ecall to print to console
ecall
jal printNewline
@@ -27,19 +27,19 @@ delimiter: .string ", "
# Print ASCII characters in the range [33:53]
li a0 33
li a1 53
- li a2 2
+ li a2 11
jal loopPrint
end:
# End program
- li a0 10
+ li a7 10
ecall
# ====== Helper routines ======
printNewline:
- la a1 newline
- li a0 4
+ la a0 newline
+ li a7 4
ecall
jalr x0 x1 0
@@ -47,18 +47,18 @@ printNewline:
# Loops in the range [a0;a1] and prints the loop invariant to console
# a0: range start
# a1: range stop
-# a2: print method (ecall ergument)
+# a2: print method (ecall argument)
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
+ # Print value in a0 as specified by argument a2
+ addi a0 t0 0
+ addi a7 a2 0
ecall
# Print a delimiter between the numbers
- li a0 4
- la a1 delimiter
+ li a7 4
+ la a0 delimiter
ecall
# Increment
addi t0 t0 1

MODIFY
examples/assembly/Factorial function
examples/assembly/Factorial function
@@ -17,7 +17,7 @@ main:
jal ra, printResult
# Exit program
- li a0, 10
+ li a7, 10
ecall
fact:
@@ -51,20 +51,20 @@ printResult:
mv t0, a0
mv t1, a1
- la a1, str1
- li a0, 4
+ la a0, str1
+ li a7, 4
ecall
- mv a1, t0
- li a0, 1
+ mv a0, t0
+ li a7, 1
ecall
- la a1, str2
- li a0, 4
+ la a0, str2
+ li a7, 4
ecall
- mv a1, t1
- li a0, 1
+ mv a0, t1
+ li a7, 1
ecall
ret

MODIFY
examples/assembly/Large program
examples/assembly/Large program
@@ -94,7 +94,7 @@ sum:
call sum
sw a0,-36(s0)
- addi a0, x0, 10
+ addi a7, x0, 10
ecall
mv sp,s1

MODIFY
examples/assembly/Shifts
examples/assembly/Shifts
slli a1,a1,8
addi a1,a1,0xff
add a2,a0,a1
- addi a0,x0,10
+ addi a7,x0,10
ecall

MODIFY
src/processorhandler.cpp
src/processorhandler.cpp
@@ -143,14 +143,24 @@ QString ProcessorHandler::parseInstrAt(const uint32_t addr) const {
}
void ProcessorHandler::handleSysCall() {
- const unsigned int arg = m_currentProcessor->getRegister(10);
+ const unsigned int arg = m_currentProcessor->getRegister(17);
+ const auto val = m_currentProcessor->getRegister(10);
switch (arg) {
case SysCall::None:
return;
+ case SysCall::PrintInt: {
+ emit print(QString::number(static_cast<int>(val)));
+ return;
+ }
+ case SysCall::PrintFloat: {
+ auto v_f = reinterpret_cast<const float*>(&val);
+ emit print(QString::number(*v_f));
+ return;
+ }
case SysCall::PrintStr: {
QByteArray string;
char byte;
- unsigned int address = m_currentProcessor->getRegister(11);
+ unsigned int address = val;
do {
byte = static_cast<char>(m_currentProcessor->getMemory().readMem(address++) & 0xFF);
string.append(byte);
@@ -158,23 +168,26 @@ void ProcessorHandler::handleSysCall() {
emit print(QString::fromUtf8(string));
return;
}
- case SysCall::PrintFloat: {
- auto v = m_currentProcessor->getRegister(11);
- auto v_f = reinterpret_cast<float*>(&v);
- emit print(QString::number(*v_f));
- return;
- }
- case SysCall::PrintInt: {
- emit print(QString::number(static_cast<int>(m_currentProcessor->getRegister(11))));
+ case SysCall::Exit2:
+ case SysCall::Exit: {
+ m_currentProcessor->finalize();
return;
}
case SysCall::PrintChar: {
- QString val = QChar(m_currentProcessor->getRegister(11));
- emit print(val);
+ QString ch = QChar(val);
+ emit print(ch);
break;
}
- case SysCall::Exit: {
- m_currentProcessor->finalize();
+ case SysCall::PrintIntHex: {
+ emit print("0x" + QString::number(val, 16).rightJustified(currentISA()->bytes(), '0'));
+ return;
+ }
+ case SysCall::PrintIntBinary: {
+ emit print("0b" + QString::number(val, 2).rightJustified(currentISA()->bits(), '0'));
+ return;
+ }
+ case SysCall::PrintIntUnsigned: {
+ emit print(QString::number(static_cast<unsigned>(val)));
return;
}
default: {

MODIFY
src/processors/ripesprocessor.h
src/processors/ripesprocessor.h
#include "../isainfo.h"
namespace Ripes {
-enum SysCall { None = 0, PrintInt = 1, PrintFloat = 2, PrintStr = 4, Exit = 10, PrintChar = 11 };
+enum SysCall {
+ None = 0,
+ PrintInt = 1,
+ PrintFloat = 2,
+ PrintStr = 4,
+ Exit = 10,
+ PrintChar = 11,
+ PrintIntHex = 34,
+ PrintIntBinary = 35,
+ PrintIntUnsigned = 36,
+ Exit2 = 93
+};
struct StageInfo {
StageInfo() {}

Change ecall to funct->a7, arg->a0-a6