qt spim syntax parser error MIPS

I have run the code below on QT SPIM and got this error: spim: (parser) syntax error on line 4 of file /Users/emily/Documents/p2.s .word this is the code in MIPS and it compiled and was able to run it on Mars. I am not sure why it is doing this in QT SPIM simulator and it has to work on the QT SPIM simulator. It is supposed to recursively do fast modular exponentiation. I have tried reinitializing and loading it and I am pretty sure that this is how you would properly declare the data types.


x: .word
k: .word
n:  word
result: .word 1
temp: .word
zero: .word 0 #for the if statement
Prompt1 : .asciiz "Enter the first integer x: "
Prompt2: .asciiz "Enter the second integer k: "
Prompt3: .asciiz "Enter the third integer n: "
Prompt4 .asciiz "The result of x^k mod n = %d/n "
# the rest of it will be after this

li, $v0, 4
la, $a0, Prompt1

# Tell the syscall that you want to read in integer
li $v0, 5
# make the syscall
sw, $v0, x

li, $v0, 4
la, $a0, Prompt2
li $v0, 5
sw $v0, k

li $v0, 4
la $a0, Prompt3
li $v0, 5
sw $v0, n

lw $a0, x
lw $a1, k
lw $a2, n

jal fme

move $t0, $v0

#Value is now saved in $t0.
#prints the prompt
li $v0, 4
la $a0, Prompt4
#prints the int
li $v0,1
la $a0,$t0

#TODO: print the prompt and then the result (in $v0)

# Move the stack pointer by 1 word
addi $sp, $sp, -32
# Store the return address
sw $ra, ($sp)
sw $s0, 4($sp)
sw $s1, 8($sp)
sw $s2, 12($sp)
sw $s3, 16($sp)
sw $s4, 20($sp)
sw $s5, 24($sp)
sw $s6, 28($sp)

move $s0, $a0   # x
move $s1, $a2   # k
move $s2, $a3   # n
lw $s3,  result # result in v0
lw $s4, $zero   # temp
# if! k > 0; skip if block
ble $s1, 0, toReturn
# if block
# set temp = fme(x, k/2, n);
# k = k/2
div $a1, $a1, 2
# call fme
jal fme
# set temp = fme
move $s4, $s3
# if k%2 == 1
# calculating k%2 by anding with 1
addi $s5, $s1, 1
bneq $s5, 1, skip
# result = x%n
div $s0, $s2
# move x%n into result
mfhi $s3

#result = (result * temp * temp) % n;
# calculate temp*temp
mul $ss6, $ss4, $ss4
# result*temp*temp
mul $s6, $s3, $s6
# (result*temp*temp)%n
div $t6, $s2
# result = (result*temp*temp)%n
mfhi $s3

move $v0, $s3
# Retore the ra from stack
lw $ra, ($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
lw $s5, 24($sp)
lw $s6, 28($sp)
addi $sp, $sp, 32
# return result
jr $ra

1 answer

  • answered 2018-02-13 02:38 Michael

    You can't just say .word without specifying an initial value.

    There's a .space directive that reserves N bytes of space without you having to specify a value, e.g. .space 4 to reserve 4 bytes of space. But that will implicitly inititialize those bytes with the value 0, so you could've just said .word 0 instead and it would've been one less character to type.

    Also, you've placed your code in the .data section which you shouldn't do, and you've failed to make your main label global.

    So right before your main label you should add:

    .globl main