For example, I have a string that only consists of characters from 1 to f(i.e. the hexes):
1f2698
It's passed in from command line as one of the argvs. How do I read each character and convert it into its corresponding integer?
1 -> 1
2 -> 2
....
f -> 15
I know we have to use the load byte instruction and manipulate the ASCII values for the characters but now sure how to put everything together. Also, since the length of the input string is uncertain, how can we count the number of bytes it has?
Could someone show me an example? I'm a beginner in MIPS assembly language, and some of the explanations of instructions I found online are really confusing, so it'd be great if you can go into more detail about how this works!
Thanks in advance:)
Assuming you're using an ASCII string, you need to convert ASCII characters to integers. For 0 to 9, this is x - 48
, where 48 is the ASCII value of 0. For a-f you have to find the offset for a-f which is x-87
.