How to convert a string into integers (in MIPS)

Click For Summary
SUMMARY

This discussion focuses on converting military time strings into integers using MIPS assembly language. The process involves validating the string to ensure it contains only base 10 characters ('0' to '9'). The conversion is achieved by iterating through the string from the end to the start, calculating the integer value using the formula: temp = temp + 10^(counter) * ('char value' - '0'), where 'counter' increments from 0 to the length of the string minus one.

PREREQUISITES
  • Understanding of MIPS assembly language
  • Familiarity with string manipulation techniques
  • Knowledge of base 10 number systems
  • Basic programming concepts such as loops and conditionals
NEXT STEPS
  • Research MIPS string handling functions
  • Learn about MIPS data types and memory management
  • Explore algorithms for validating string formats
  • Study integer arithmetic in MIPS assembly
USEFUL FOR

Students in computer organization courses, MIPS assembly language programmers, and anyone interested in string manipulation and integer conversion techniques.

Rat_Rodz
Messages
1
Reaction score
0
Hey,

I'm working on a project for my Computer Organization class and I have to read in 2 separate times (in military format with no ":" ) as strings and then find and print the time difference. I am able to read in and save the strings no problem, but I don't have a clue as to how I can manipulate them into integers. any suggestions? ...I would post the code that I have already, but I'm not sure as to how to go about it.
 
Technology news on Phys.org
Rat_Rodz said:
Hey,

I'm working on a project for my Computer Organization class and I have to read in 2 separate times (in military format with no ":" ) as strings and then find and print the time difference. I am able to read in and save the strings no problem, but I don't have a clue as to how I can manipulate them into integers. any suggestions? ...I would post the code that I have already, but I'm not sure as to how to go about it.

Hey Rat_Rodz and welcome to the forums.

The first thing to do is to make sure that the string is valid. For the moment let's assume that the string is required to be only in base 10 (ie only have characters '0' to '9').

So assuming we string has the correct format, the rest is pretty easy.

Going from end of string to start of string we start off with our temp variable to be zero.
For each character we do temp = temp + 10^(counter) * 'value of digit'.

The digit will be calculated by using the relationship 'value of digit' = 'char value' - '0'. counter will increment in a natural loop from 0 to string_len-1.
 

Similar threads

Replies
1
Views
2K
  • · Replies 47 ·
2
Replies
47
Views
4K
Replies
5
Views
1K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
55
Views
7K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K