MIPS: Saving a String to register(s)?

  • Thread starter Thread starter pags920
  • Start date Start date
  • Tags Tags
    Mips String
Click For Summary
SUMMARY

This discussion focuses on implementing a MIPS program to convert letters into a phone number format. Users are advised to store the input string in memory rather than registers, allocating space in the data segment for both input and output strings. The conversion process involves using ASCII values for characters, with conditional branches to map letters to corresponding numbers based on traditional phone keypad layouts. The logic for conversion is outlined, emphasizing the need for multiple lines of code due to the nature of assembly programming.

PREREQUISITES
  • Understanding of MIPS assembly language syntax and structure
  • Familiarity with ASCII character encoding
  • Knowledge of conditional branching in assembly programming
  • Experience with memory management in MIPS (data segment allocation)
NEXT STEPS
  • Research MIPS assembly language input/output operations
  • Learn about ASCII character manipulation in assembly
  • Explore different phone keypad layouts and their implications on character mapping
  • Study advanced MIPS programming techniques for optimizing code efficiency
USEFUL FOR

Students and developers working on MIPS assembly programming, particularly those interested in string manipulation and character encoding for applications like phone number conversion.

pags920
Messages
20
Reaction score
0

Homework Statement



I am currently working on a MIPS program that is supposed to convert letters, either lowercase or uppercase, to a phone number.

Two questions:

1. With the user entering a string, how do I go about in saving the string into the registers? Or would memory be a more convenient choice?

2. Does anyone have any strategies or hints as to how I can go about in converting the string into numbers? One thought I had was to use the ASCII chart with conditional branches, but that would involve many lines of code.

Below is only the Main subroutine.

The Attempt at a Solution


Code:
#INITIALIZATION
.data
msg0:	.asciiz "Please enter the phone number, expressed in letters, that you wish to convert.\n"
msg1:	.asciiz "You have entered: \n"
msg2:	.asciiz "The phone number you entered is invalid.\n"
msg3:	.asciiz "The phone number you entered is valid.\n"
msg4:	.asciiz "Your phone number, converted from letters to numbers, is \n"
nl:	.asciiz "\n"

str:	.space 7

#############################################
# 		Main
############################################# 
.text
.globl main
main:
	la $a0, msg0
	li $v0, 4
	syscall

	la $a0, str
	li $a1, 8
	li $v0, 8
	syscall

	la $a0, nl
	li $v0, 4
	syscall

	la $a0, msg1
	li $v0, 4
	syscall

	la $a0, str
	li $v0, 4
	syscall
 
Physics news on Phys.org
pags920 said:

Homework Statement



I am currently working on a MIPS program that is supposed to convert letters, either lowercase or uppercase, to a phone number.
Caveat: I haven't done any programming on MIPS machines, but I have done a fair amount of assembly programming using Intel x86 assembly and some on Motorola 68000.
pags920 said:
Two questions:

1. With the user entering a string, how do I go about in saving the string into the registers? Or would memory be a more convenient choice?
I would put the phone number string in memory. Your program would allocate space for the input string and output string of digits in the data segment with the other variables, and your input routine would take input from the user and store it in the input string variable. Another part of your program (a different routine is my recommendation) would store the converted string of digits in the other variable. If you're working with local (not long-distance) US phone numbers, seven bytes each would suffice, and that seems to be what you're doing in the code you show.
pags920 said:
2. Does anyone have any strategies or hints as to how I can go about in converting the string into numbers? One thought I had was to use the ASCII chart with conditional branches, but that would involve many lines of code.
Lets' face it - you're writing assembly code, so most things you do are going to require many lines of code.

As far as using ASCII codes for the characters, you should do this for sanity checking - to make sure that your input values are actually characters, and to convert any lower-case letters to upper case. The ASCII codes for A through Z are 65 through 90 (0x41 through 0x5A in hex) and for the lower-case letters, they are 97 through 122 (0x61 thorough 0x7A). You will need to use conditional branches to convert the characters to the corresponding numbers.

You'll need to make some assumptions as to how the phone keypad is laid out. The old rotary-dial phones didn't have Q or Z, and laid out the remaining 24 letters equally on the numbers 2 through 9. My Panasonic wireless home phone and Nokia cell have a different arrangement, with PQRS on the 7 key and WXYZ on the 9 key, and three letters each on the other seven keys.

The logic (shown here roughly in C) would go something like this, assuming you have already validated your input data and converted lower-case letters to upper case:
Code:
for (i = 0; i < 7 ; ++i)
{
   if(char == 'A' OR char == 'B' OR char == 'C') outString[i] = '2';
   else if (char == 'D' OR char == 'E' OR char == 'F') outString[i] = '3';
   else if (char == 'G' OR char == 'H' OR char == 'I') outString[i] = '4';
   .
   .
   .
}
pags920 said:
Below is only the Main subroutine.

The Attempt at a Solution


Code:
#INITIALIZATION
.data
msg0:	.asciiz "Please enter the phone number, expressed in letters, that you wish to convert.\n"
msg1:	.asciiz "You have entered: \n"
msg2:	.asciiz "The phone number you entered is invalid.\n"
msg3:	.asciiz "The phone number you entered is valid.\n"
msg4:	.asciiz "Your phone number, converted from letters to numbers, is \n"
nl:	.asciiz "\n"

str:	.space 7

#############################################
# 		Main
############################################# 
.text
.globl main
main:
	la $a0, msg0
	li $v0, 4
	syscall

	la $a0, str
	li $a1, 8
	li $v0, 8
	syscall

	la $a0, nl
	li $v0, 4
	syscall

	la $a0, msg1
	li $v0, 4
	syscall

	la $a0, str
	li $v0, 4
	syscall
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 22 ·
Replies
22
Views
5K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
13K