Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 27, 2007, 04:26 PM   #1
notwist
macrumors regular
 
Join Date: Dec 2006
Location: New Brunswick, NJ
mips help!

I'm trying to get a user to enter in a string of characters and then parse each character and save them into each of their own registers. So far i have the user entering the string, but i don't know where the string is stored.

li $v0, 8
la $a0, expr
li $a1, 20
syscall

For example if someone enters in the string '56+'. In ASCII, the string is represented by 3 sets of 2 numbers. i want to store the 56 and + in their own registers. How can i do this? I know there's a sb and lb instruction, but I'm not sure how to implement since I don't even know how to load the input string!
notwist is offline   0 Reply With Quote
Old Jan 28, 2007, 05:09 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by notwist View Post
I'm trying to get a user to enter in a string of characters and then parse each character and save them into each of their own registers. So far i have the user entering the string, but i don't know where the string is stored.

li $v0, 8
la $a0, expr
li $a1, 20
syscall

For example if someone enters in the string '56+'. In ASCII, the string is represented by 3 sets of 2 numbers. i want to store the 56 and + in their own registers. How can i do this? I know there's a sb and lb instruction, but I'm not sure how to implement since I don't even know how to load the input string!

You are the optimist! I'll post a proper reply as soon as Apple releases a Macintosh that uses a MIPS processor.
gnasher729 is online now   0 Reply With Quote
Old Jan 28, 2007, 06:40 AM   #3
mufflon
macrumors 6502
 
Join Date: Sep 2006
I believe there are some better commands for entering / managing text in the consiole (which I think it is), however they are somewhere else (@uni) and I would really like to know what this is for - learning assembly is kinda uni-related as well and if this is a home assignment you should better tell us as much...


.. I would propose you use som basic c-derivate which is available for mips - it'll make this easier.
mufflon is offline   0 Reply With Quote
Old Jan 31, 2007, 10:23 PM   #4
LtRammstein
macrumors 6502a
 
Join Date: Jun 2006
Location: Denver, CO
Send a message via AIM to LtRammstein Send a message via MSN to LtRammstein
To begin, it's funny that mentioned that you won't touch MIPS until they make a Mac compiler. FYI, all compilers use assembly code, it's just MIPS was the first, then came the others from Intel and IBM. Visual Studios.NET 2005 uses the x86 Assembler.

Now the question at hand. Parsing it in C would give you the best idea on what to write, but I think you would need to do it differently.

Code:
li $v0, 8
la $a0, expr
li $a1, 20
syscall
You would need to define variables in the .data function to use. Second, you would have to use a specific command, in this case, you can use a variable named string1 and have it be a .ascii variable type. The .ascii means that what is inputted to it is a basic ASCII character. Two, you'd need to define an array. For this you would have to use array: .space 40. Remember MIPS does everything by a word (4 bits) so if you want an array of 10 items you need to multiply it by 4 to get the right space.

From here you can then put each individual character into a register, probably a $t0-9 or $s0-9 register.

Hopefully you understand that you will need at least 2 loops to do this.

By the way, I am in a MIPS programming class at my uni, and right now I have a homework due Wednesday on recursive programming in MIPS (which is a total pain in the ass).

Hopefully this explanation helps!

Steve
__________________
17" White Intel iMac 1.83GHz, 250 GB HD, 2 GB RAM || iPod Touch 16GB w/ 3.0 || 15" Intel MBP 2.4GHz, 250 GB HD, 4 GB RAM

Last edited by LtRammstein; Feb 1, 2007 at 02:12 PM. Reason: Checked class' website to confirm due date.
LtRammstein is offline   0 Reply With Quote
Old Feb 6, 2007, 01:52 PM   #5
notwist
Thread Starter
macrumors regular
 
Join Date: Dec 2006
Location: New Brunswick, NJ
Quote:
Originally Posted by LtRammstein View Post
To begin, it's funny that mentioned that you won't touch MIPS until they make a Mac compiler. FYI, all compilers use assembly code, it's just MIPS was the first, then came the others from Intel and IBM. Visual Studios.NET 2005 uses the x86 Assembler.

Now the question at hand. Parsing it in C would give you the best idea on what to write, but I think you would need to do it differently.

Code:
li $v0, 8
la $a0, expr
li $a1, 20
syscall
You would need to define variables in the .data function to use. Second, you would have to use a specific command, in this case, you can use a variable named string1 and have it be a .ascii variable type. The .ascii means that what is inputted to it is a basic ASCII character. Two, you'd need to define an array. For this you would have to use array: .space 40. Remember MIPS does everything by a word (4 bits) so if you want an array of 10 items you need to multiply it by 4 to get the right space.

From here you can then put each individual character into a register, probably a $t0-9 or $s0-9 register.

Hopefully you understand that you will need at least 2 loops to do this.

By the way, I am in a MIPS programming class at my uni, and right now I have a homework due Wednesday on recursive programming in MIPS (which is a total pain in the ass).

Hopefully this explanation helps!

Steve
Thanks. If I am just reading each seperate char and putting into a register, what is the array for? Also, How do I distinguish between when a person enters a 1 digit or 2 digit number? Argh I hate this class!
notwist is offline   0 Reply With Quote
Old Feb 7, 2007, 02:50 PM   #6
LtRammstein
macrumors 6502a
 
Join Date: Jun 2006
Location: Denver, CO
Send a message via AIM to LtRammstein Send a message via MSN to LtRammstein
This is the great part about programming!

Look at this code and see if it helps you understand.

Code:
move $t2 $a0 # $a0 is the array
li $t0, 0 # Index variable
move $t1 $v0 # The size of the array to use

insertLoop:
bge $t0 $t1 loopDone

li $v0 5
syscall
sw $v0 ($t2)

addi $t0 $t0 1
addi $t2 $t2 4

j insertLoop

loopDone:
jr $ra
That is an insertion loop to the array. After the user inputs a character or number they MUST HIT ENTER for it to be stored in the array. So they can have them be double digit number.

To be safe, I recommend allocating space on the stack.

Lets say they put 5 items in the array. Make sure you have the array size in a $s0 register. From there you can use the rest of the $s0 and $t0 registers to put those items in the array, that of course is another loop.

Hopefully this makes sense.

Steve
__________________
17" White Intel iMac 1.83GHz, 250 GB HD, 2 GB RAM || iPod Touch 16GB w/ 3.0 || 15" Intel MBP 2.4GHz, 250 GB HD, 4 GB RAM
LtRammstein is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 09:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC