arrays - Calculating length of sub strings of consecutive characters MIPS -
I am writing a program using MIP which takes an input string from the user and is the longest substrings of the same character continuously Does. My problem is that the program reaches 'end' before the 'target' string is out. Any help is appreciated!
main: La $ a0, input_ms g # user li $ v0.4 syscall li $ v0, 8 input warning, memory la $ a0, input_string li $ a1, 100 syscall li $ t0 , 0a $ t1, input_string # First element address of lb $ a0, ($ t1) # input_string [0] (first letter) $ s0, $ a0 # current_char = read_char moves (); Transfer $ S1, $ a0 # previous_char = input_string [0]; Transfer to $ S2, $ a0 # last_char = input_string [0]; Li $ s3, 1 # current_num_chars = 1; Li $ s4, 1 # last_name_kar = 1; La $ T5, New_Lin Loop: ADI $ T, $ T, For # 1 (K = 1; K = last_name_kar) {move $ s1, $ s0 j loop # else do not grow anything _final: move $ s2, $ s0 # final_char = current_char; Transfer to $ S4, $ s3 # last_name_chairs = current_name_flare; Move $ S1, $ s0 j Loop #}: move $ s1, $ s0 j loop # else {# current_num_chars = 1; #} Print_final: La $ a0, output_msg li $ v0, 4 syscall li $ t2, 0 print_chars: li $ t2, for # (k = 0; k & lt; final_num_chars; k ++) {beq $ t2, $ S3, end move $ a0, $ s2 # print_char (final_char); Li $ v0, 11 syscall j print_chars #} inter: li $ v0, 4 # print_string ("\ n"); La $ a0, new_line syscall li $ v0, 10 # exit () syscall
To compare print_chars
loop to $ t2
(which is set to bus 0), compare $ s3
to jump to the end For or not. Thus, it will always make a similar comparison, and your loop will either exit or never end.
Plus, this comment explains that you should compare $ s4
, not $ s3
.
Comments
Post a Comment