I want to translate this java code into MIPS. I get a syntax error. can you tell me what I am doing wrong. Java
public static void setCount(int count)
{
IntegerMath.count = count;
}
Mips
.globl setCount
#---------------
.text
setCount: #-----------------
lw count($0), $t0
jr $ra
#----------------------------- `
Java
System.out.println(IntegerMath.getCount());
int a = new Scanner(System.in).nextInt();
IntegerMath.setCount(a);
System.out.println(IntegerMath.getCount());`
Mips
#--------------------------------------------------
jal getCount #System.out.println(IntegerMath.getCount())
add $a0, $0, $v0
addi $v0, $0, 1
syscall
#-----------------------------------------------------
addi $v0, $0, 5 # readInt make new variable
syscall
add $t0, $0, $v0 #set t0 to value
#------------------------------------------
jal setCount
add $a0, $0, $v0
#-------------------------------
addi $v0, $0, 1
syscall
#-------------------------
addi $sp, $sp, 4
lw $ra, 0($sp)
jr $ra
Your problem is this line in your "setCount" method:
lw count($0), $t0
Load Word cannot be used in this way! You can't use
count
as an operand.If you are attempting to load
count
into $t0, do this:lw $t0, count($0)
I would encourage you to use the MARS MIPS Emulator. It has built in error-checking that works, quite well.
SIDE NOTE: Just a bit about your formatting. While it's not critical, it is syntactically more acceptable to format your
addi
statements as follows, for easier readability:Also, this one.
add $a0, $v0, $zero