I'm relatively new to MIPS and am using SPIM as my compiler. The program I am trying to write takes a user's input of a decimal integer and determines how many zero's and one's are in the binary representation of it:
.data
ques: .asciiz "Enter a decimal integer:\n"
zer: .asciiz "Number of 0's\n"
one: .asciiz "Number of 1's\n"
buf: .word 16
ans: .word 40
.text
.globl main
#Prompt user for number
main:
la $a0, ques #asks user to enter decimal integer
li $v0, 4
syscall
#Read the input
li $v0, 5 #reads user input
syscall
move $s3, $v0 #stores user input in register
jr count #jumps to count function
count:
addi $s7, $s7, 1 #increments with each run of the loop
beq $s7, 32, end #checks if all parts of the binary integer have been checked
andi $s0, $s3, 1 #ands one to binary number
beq $s0, 0, zeros #goes to incrementing function for 0
beq $s0, 1, ones #goes to incrementing function for 1
zeros:
addi $s5, $s5, 1 #increments 0 counter by one
srlv $s3, $s3, 1 #shifts binary digit right by one
j count #returns to count function
ones:
addi $s6, $s6, 1 #increments 1 counter by one
srlv $s3, $s3, 1 #shifts binary digits right by one
j count #returns to count function
end:
la $a0, zer #Prints zeros header
li $v0, 4
syscall
la $a3, $s5 #prints number of zero's
li $v0, 1
syscall
la $a0, one #prints ones header
li $v0, 4
syscall
la $a3, $s6
li $v0, 1
syscall
jr $31 #end program
My problem is that when I try to print the results of my program, I get a syntax error:
spim: (parser) syntax error on line 43 of file test.mal
la $a3, $s5 #prints number of zero's
^
I've tried a number of things to fix this, but I'm not really even sure what the problem is. Any suggestions would be helpful.