•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
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??
(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??
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
Please:
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.
•
•
•
•
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.
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
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??
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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).
- 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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Binary GCD algorithm in MIPS (Assembly)
- MIPS Recursive Programming, Help please! (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: arrays
- Next Thread: help me,its urgent, PC Alarm clock ASM code



Linear Mode