User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 455,982 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 1064 | Replies: 5
Reply
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

Question help me with doing this recursively in MIPS

  #1  
Nov 28th, 2007
So I am asked to write a function called parens that will allow me to do this. Say that I have a string (a + (x) * (6 + 14) - q7), then I will get:
(x)
(6 + 14)
(a + (x) * (6 + 14) - q7)


the function parens takes a parameter which is the address of the starting string which is always a '('. The base case here is when it finds ')' then it prints another function called printFormula that takes two parameter, one is the address of the '(' ($a0) and the number of chars to be printed ($a1). Whenever it sees a '(' then it will call the function parens again. My confusion is that what should I do when it's not a '(' or a ')' ?? Can someone help me to develop this function??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help me with doing this recursively in MIPS

  #2  
Nov 28th, 2007
Don't do anything. Just go to the next character. Remember, all you have to do is find matching ().

It would help you an awful lot if you get out a piece of graph paper and draw yourself one of these equations, then figure out how to find and handle each piece yourself.

Hope this helps.
Reply With Quote  
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

Re: help me with doing this recursively in MIPS

  #3  
Nov 28th, 2007
Originally Posted by Duoas View Post
Don't do anything. Just go to the next character. Remember, all you have to do is find matching ().

It would help you an awful lot if you get out a piece of graph paper and draw yourself one of these equations, then figure out how to find and handle each piece yourself.

Hope this helps.



and what do I do when I get the address of the next character? do I make a recursive call or do I have to jump to the base case? do I actually need to know the length of the string to do this function? do I need somekind of register to track the character in the string one by one?? or is the $a0 (which is one of the function parameter which takes in the address of the starting string, always a '(' in this case). used to do that?? I suppose that the $a0 is changed whenever I found another '(', therefore I can just pass the $a0 whenever I want to print the formula
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help me with doing this recursively in MIPS

  #4  
Nov 29th, 2007
Please:
It would help you an awful lot if you get out a piece of graph paper and draw yourself one of these equations, then figure out how to find and handle each piece yourself.

Do that and you'll find an answer to a lot of your questions. The way you keep data in memory and the way you access that data is all up to you.

Hope this helps.
Reply With Quote  
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

Re: help me with doing this recursively in MIPS

  #5  
Nov 29th, 2007
I tried to make a sketch in a paper,and tried to do this in java language first.. however I have one problem.. if the currentChar is not a '(' or a ')' then I will have to go to the next index of the string right. Then what do I have to do when I go to the next index of the string?? How do I make that so it goes and check again?? How do I know that the next index of the string is not beyond the strings limit, without having to know the strings length??
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help me with doing this recursively in MIPS

  #6  
Nov 29th, 2007
There are two pieces of information you need to keep track of:
- where am I in the string?
- how many '('s have I found?

You start out at the first character in the string, with zero '('s found so far.

I suggest you make your function recurse when it finds a '('.

Hope this helps.

[EDIT] Yes, how do you know you are at the end of the string?
In C, the string ends at the first character with a value of zero (not '0', which is a value of 48).
Last edited by Duoas : Nov 29th, 2007 at 9:18 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Assembly Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 9:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC