简体   繁体   中英

comparing characters in string MIPS

there I'm currently trying to write a MIPS program that will sort the user inputted String and Bubble sort it. A being the in the front and Z last.

Right now I'm kind of confused on how I can compare each individual character in the string. So for example:

String: Stackoverflow Compare S and T the first two letters. Since S is belongs in the front it stays and no swap happens.

How would I go about moving onto the next set of characters to compare so T and A would be the next set to compare.

I think I would use the lb (load byte) instruction but I'm not entirely sure of to use the offset correctly.

Thanks for the help.

Just as a reminder, in the loop, you must check whether the current pointer is > than the index (base pointer + length of the string - 1), or you can also check the value at index (current pointer + 1) equals to 0 (NUL) string terminating character or not.

Make sure you keep a copy of the base pointer somewhere (in register or memory).

In each loop, you will read the character currently pointed to by the current pointer by load byte at current pointer with offset 0, and read the next character by load byte at current pointer with offset 1. Then you can do the comparison and swapping. After that, you increase the current pointer by 1 (since a character in ASCII is 1 byte, you will increase the address by 1 byte only).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM