I have this assembly project (mips) but I think I have an overflow problem....

The problem is that the answer is ok until number 99 but at 100 it prints with a - infront of the number. The projects just ask me to calculate a sum (x+a)^2 (x= 1 to 100) and a= (1+2y) (y= 1 to x)

The answer i get is:
Result: -2088573816

I post the code:

``````.data # data segment. We Define the Constants here
intro: .asciiz "\n\t\t\t\tCalculate Sum-Test\n\n"
msgIn: .asciiz "\nPlease give an integer between 1 - 100: "
error: .asciiz "\nInvalid Number: Integer must be between 1-100\n\n"
thx: .asciiz "\n\nThank you for using our program"
res: .asciiz "\nThe result is: "
mo: .asciiz "\nThe average is: "
rest: .asciiz "\nThe modulo is: "

######################################…
.text # text segment
.globl main

main:
#constants
li \$t0, 100
li \$t1, 1
li \$t2, 2

#counters
li \$t3, 1 #counter for the first loop
li \$t4, 1 #counter for the second/nested loop

#sum
li \$s1, 0 #\$s1 is the a value
li \$s2, 0 #\$s2 holds the final result

# Print on consule the intro message
la \$a0, intro # Message that indicates the title of the current program
li \$v0, 4 # System code for print string
syscall # Print String
j loop1

error_msg:
# Print on consule the error message
la \$a0, error # Message that indicates the error of the current program
li \$v0, 4 # System code for print string
syscall # Print String

loop1:
# Print on consule the instruction message
la \$a0, msgIn # Message that indicates the instructions of the current program
li \$v0, 4 # System code for print string
syscall # Print String

#Read an integer from keyboard
li \$v0, 5 # System code for reading an integer
syscall # Read an integer
move \$s0,\$v0 # Save integer in \$s0

# By this time the value should be in \$s0 register

######################################…
# This is code that checks if the integer is between 1 - 100
######################################…

#Checks if integer>100
bgt \$s0, \$t0, error_msg #pseudoinstruction, \$s0>\$t0 (user_int>100)

#Checks if integer<1
blt \$s0, \$t1, error_msg #pseudoinstruction, \$s0<\$t1 (user_int<1)

######################################…
# This is code generates the a value of the serie
######################################…

#This loop calculates the final result
for_loop_x:

#Checks if first_loop_counter<user_value
bgt \$t3, \$s0, loop_out #pseudoinstruction, \$t3<\$s0 (counter<user_int)

for_loop_a:

#Checks if second_loop_counter<first_loop_counter
bgt \$t4, \$t3, calculate #pseudoinstruction, \$t4<\$t3 (second_loop_counter<first_loop_…

#Calculate the a value
mulou \$t5, \$t2, \$t4 #multiply \$t5=\$t2*\$t4 (\$t5= 2*second_loop_counter => 2*y)
addiu \$s5, \$t5, 1 #add immitiade \$s5=\$t5+1 (\$s5= 1+\$t4 => 1+2*y)
addu \$s1, \$s1, \$s5 #add immitiade \$s1=\$s1+\$s5 (\$s1= \$s1+\$s5 => sum=prev_value+(1+2*y)) ==> This is the a value
addiu \$t4, \$t4, 1 #increase counter by one (\$t4=\$t4+1)
j for_loop_a #Check the condition again

calculate:

addu \$t6, \$t3, \$s1 #add \$t6=\$t3+\$s1 (\$t6= first_loop_counter+a value => x+a)
mulou \$t7, \$t6, \$t6 #calculate square root \$t7=\$t6*\$t6 (((x+a)^2)
addu \$s2, \$s2, \$t7 #calculate the final sum \$s2=\$s2+\$t7

addiu \$t3, \$t3, 1 #increase counter by one (\$t3=\$t3+1)

j for_loop_x #Check the condition again

loop_out:

# Print on consule the result message
la \$a0, res # Message that indicates the results of the current program
li \$v0, 4 # System code for print string
syscall # Print String

#Printing results on consule
move \$a0, \$s2 #moves the final result to the argument 1
li \$v0, 1 #System code for printing an integer
syscall #Print Integer

end:
######################################…
# Print on consule the "thank you" message

la \$a0, thx
li \$v0, 4
syscall

#Exiting system
li \$v0, 10 # exit system call
syscall``````

thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.
{"ft_lang_label":"__label__en","ft_lang_prob":0.53622854,"math_prob":0.76101106,"size":3716,"snap":"2021-04-2021-17","text_gpt3_token_len":1220,"char_repetition_ratio":0.16756466,"word_repetition_ratio":0.11073254,"special_character_ratio":0.37890205,"punctuation_ratio":0.1294964,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9672448,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-19T02:31:26Z\",\"WARC-Record-ID\":\"<urn:uuid:d00fd7cc-2711-433f-bb51-dee72fffd5f2>\",\"Content-Length\":\"54883\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:24a8574d-cd57-457c-9581-89b56d5a5d94>\",\"WARC-Concurrent-To\":\"<urn:uuid:d86b6cae-716a-4571-9eaf-40d54d9069fb>\",\"WARC-IP-Address\":\"172.67.7.242\",\"WARC-Target-URI\":\"https://www.daniweb.com/programming/software-development/threads/383933/can-t-figure-it-out-why-not-printing-the-number-assembly-newby\",\"WARC-Payload-Digest\":\"sha1:WFVRV7OLNZNPTHMF657PGHO52BX5KDJX\",\"WARC-Block-Digest\":\"sha1:2EOR3Z2T4KU45QXTGSXCJE7C62QACJWK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038863420.65_warc_CC-MAIN-20210419015157-20210419045157-00430.warc.gz\"}"}