Basically title.

Part of a larger program, but I can't figure out how to remove just the first letter (it's always not a number; A, B, C, X, etc.), and is always followed by numbers. So essentially, I'm trying to get "x234" to "234".

I figured I could use lb $a0, 1($t0) to load the 2, then lb $a0, 2($t0) to load the 3, but I don't know how I could do that reliably for X character-long entries. I'm very new to MIPS (from a java background).

Is there any fairly simple way to do this in mips?

Recommended Answers

All 5 Replies

In many systems the string resides at some address and here's the trick. Think about how you print that string.
You pass the address of where the string is to the print function. Now to skip the first character, add 1 to the address and pass that address to the print or copy function.

That's clever, thanks!

(Works as far as a couple quick examples can tell).

Exactly what I was looking for. Nice and clean. Thanks a ton!

Quick follow up: Are there any such tricks that would work for integer values? Say I've just added 5 to an int, but need the first character removed, how would I change this approach to suit the fact that I'm dealing with an int (and adding 1 would just, well, add 1)?

Well an Integer is not a string so let's for giggles add 5 to 9 and the result is (integer) 14. We can't print that yet since it's not a string or characters. So there should be a function to convert integer to string and then the same pointer increment used to print out 4.

I figured that was the only way (unfortunately), but thanks a bunch anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.