Jump to content

[MIPS]Need help with some code!

- - - - -

  • Please log in to reply
1 reply to this topic

#1
chaddi_90

chaddi_90

    Newbie

  • Members
  • Pip
  • 1 posts
Hello!


I am new to this forum and to the mips system. My task is to construct two subroutines for a program.

#-----------------------------------------------------------
# PROCEDURE: check_string
#
# DESCRIPTION: This procedure checks if the string contains
# integers separated with a plus-signs, e.g,
#
# int+int+int+...+int
#
# INPUT: $a0 - the address of the string
# $a1 - the length of the string
#
# OUTPUT: $v0 = 1 if the string is invalid
# $v0 = 0 if the string is valid
#-----------------------------------------------------------

and

#-----------------------------------------------------------
# PROCEDURE: int_to_string
#
# DESCRIPTION: This procedure converts an integer to a
# string. It assumes that the string is large
# enough for the number, and that the number
# is smaller than 2147483648. The end-of-string
# should be marked with a null-byte. The
# maximum string length should though be 11
# bytes.
#
# INPUT: $a0 - the number to be converted
# $a1 - the address of the string
#
# OUTPUT: None.
#-----------------------------------------------------------

I have started writing some code on the first subroutine,check string, this is how far I have come:

buffer:	.space 80 # the place for the input-string


li	$v0, 8

	la	$a0, buffer

	li	$a1, 80

	syscall 


I know i have to do a loop function, but not sure how to do it, is their anyone that can help?

Edited by dargueta, 22 April 2011 - 09:37 AM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
That really depends on what you need the loop to do. For example, this

int max = ...something...

for( int i = 0; i < max; ++i )

    ...more code in here...


Would be:

addu    $t0, $0, $0

# assume max is in $t1


loop_top:

    # code for the loop in here

    addiu   $t0, $t0, 1

    bne     $t0, $t1, loop_top


However, this:

 while( myfunc() != 0 )

    ...something...


is completely different:

loop_top:

    jal     myfunc

    beqz    $v0, loop_end

    

    # code in here

    j   loop_top

    

loop_end:

# more code after the loop


sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users