splurchner 0 Newbie Poster

The following program is written in MIPS and is supposed to calculate values based on the input of an integer. When its run through SPIM I get an error on the last line that doesn't make any sense to me. If anyone can tell me whats wrong it would be greatly appreciated.

# Adam Ross Cohen 000891451 AC239258@albany.edu
# CSI333 Fall 2009 Wed 12:35 Discussion Section
# This is program 5 part a.
# This program prompts the user for an integer,
# reads in said integer,
# counts the number of 1s in the binary representation of the integer,
# finds the highest power of 2 that evenly devides the integer,
# finds the sum of the decimal digits of the integer,
# and lastly returns the calculated values to the user.

      	     .data
prompt:	     .asciiz "Input an integer: "  # prompt string
ones:	     .asciiz "Number of 1's in the binary representation of the integer: "
twos:	     .asciiz "Highest power of two that will evenly devide the integer: "
dig:	     .asciiz "The sum of the decimal digits: "
newline:     .asciiz "\n"
	     .text
	     .globl main
# Function main
main:
# Prompt the user
  	 la $a0, prompt
	 li $v0, 4
	 syscall
# Read in the integer
       	 li $v0, 5
	 syscall
# Set temp0 as the integer value
      	 move $t0, $a0 # int value
# Set temp1 temp2 and temp3 to zero for use as counters
      	 move $t1, $0 # counts zeroes at the end of the binary representation
	 move $t2, $0 # counts the number of ones in the binary representation
	 move $t3, $0 # for use as a loop counter
# Set temp4 for use as a mask
      	 move $t4, $0 # set to zero
	 addi $t4, $0, 1 # make the mask 1
	 sll $t4, $t4, 31 # shift the mask to make it 10000000000000000000000000000000
# set the loop counter to 32
      	 addi $t3, $0, 32
# loop through each bit and keep track the ones and zeroes
loop:
	 move $t5, $0
	 and $t5, $t0, $t4
	 beq $t5, $0, its_zero
	 bne $t5, $0, its_one
back:
	 srl $t4, $t4, 1
	 addi $t3, $t3, -1
	 bne $t3, $0, loop
# set the mask (temp4) to 10 and the loop counter (temp3) to zero to hold the sum
      	 move $t3, $0
	 addi $t4, $0, 10
# divide the int by 10 to get each digit and then add it to the sum (temp3)
loop2:
	 div $t0, $t4 # divide the int by 10
	 mfhi $t6 # move the remainder to temp6
	 mflo $t0 # replace the int with the quotient
	 add $t3, $t3, $t6 # add the remainder to the sum
	 bgez $t0, loop2
# print out the number of ones in the binary representation
  	 la $a0, ones
	 li $v0, 4
	 syscall
	 move $a0, $t2
	 li $v0, 1
	 syscall
	 la $a0, newline
	 li $v0, 4
	 syscall
# print the highest power of two that the integer is evenly divisible by
  	 la $a0, twos
	 li $v0, 4
	 syscall
	 move $a0, $t1
	 li $v0, 1
	 syscall
	 la $a0, newline
	 li $v0, 4
	 syscall
# print the sum of all the digits in the integer
  	 la $a0, dig
	 li $v0, 4
	 syscall
	 move $a0, $t3
	 li $v0, 1
	 syscall
	 la $a0, newline
	 li $v0, 4
	 syscall
# end the program
      	 li $v0, 10
	 syscall

# Function its_zero
its_zero:
	addi $t1, $t1, 1 # incriment zeroes counter by one
	j back # return

# Function its_one
ins_one:
	addi $t2, $t2, 1 # incriment ones counter by one
	move $t1, $0 # set the zeroes counter back to zero
	j back # return

the output from SPIM when I load the program is as follows

spim: (parser) syntax error on line 103 of file p5a.mal
          j back # return
          ^
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.