1,105,333 Community Members

MIPS code : Print 3rd, 5th & 7th character from 10 character string?

Member Avatar
wasiqjaved
Newbie Poster
1 post since Jan 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, Need some help with MIPS

I need to write a MIPS code that reads 10 characters string and then only print out value of 3rd, 5th and 7th character (remembering that first character is character 0)

OUTPUT (should be somewhat like this):

Enter 10 character string : i love you
The 3rd character : l
The 5th character : v
The 7th character :

I'm relatively new to this MIPS and need some help. Would greatly appreciate it!

Member Avatar
DeanMSands3
Posting Whiz
358 posts since Jan 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 49 [?]
Skill Endorsements: 2 [?]
 
0
 

Well, to start, setup a space for your string for 11 bytes(trailing zero) and put that in your data section.
Also, put your string prompts into the .data section. (i.e. "Enter 10 character string: ")
Then, in your main program, you print the prompting string (you know how to use syscall, right?)
Point the $A0 at the input string buffer.
Use the syscall for reading an input string.

Repeat this block for characters 2, 4, 6
Print out the first output text ("The 3rd character: ")
Load an immediate 2 (being the 3rd number) into a temporary register like $t0.
Use a load byte for $a0 from your input string offset by that register.
Use the print byte syscall.
Repeat (or just copy/paste)

And syscall to exit.
Happy coding!

EDIT: For sanity's sake, start your "The 3rd character: " with New Lines (i.e. "backslash n"). That way, when you print you character, and then the next string, it won't be jammed together.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: