Question

It's a MIPS question. Can anyone explain what's happened in the loop? Thank you. I need a deep explanation.

Ma1n SvO, 4 $a0, stri1 # print string upper case 14 syscall $v0, 4 $a0, string 16 # print string ABCDEFG. 18 syscall v0, 4 $a0, str2 19 # print string lower case 21 syscall 23 1oo 24 25 26 $t1, string($tO) beq $t1, $zero, exit blt $t1, A, continue bgt $t1, 2, conti addi $t1, $t1, 0x20 sb #t0 to t1 # if t1 =0 goto exit # if t1 < A goto continue # if t1 > goto continue $tl, string($to) 31 continue addi $t0, $t0, 1 loop 32 35 exit $v0, 4 $a0, string 36 38 syscall vo, 10 syscall data 43 string: asciiz ABCDEFG 44 strl 45 st2: asciiz nLower case 46 ascilz Upper case Line: 11 Column: 1 Show Line Numbers Mars MessagesRun IIO Upper case ABCDEFG wer case: abcdefg Clear program 1s Tini shed running

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In loop, line 24,

$t0 is initially zero (0).

lb $t1, string($t0) --> this line takes the 1st element of string. (Index starts from 0).

Therefore t1 = 'A' , in other words it is equal to ascii decimal 65. The hexa value is 41.

For the table below, first column is decimal, next is hexa, then octa, then character and finally its name.

61 3D 75- 623E 76> 63 3F 77 64 |40 100@ 65 41 101 A 66 42 102 B 6743 103 C 6844 104D 69 45 105 E 70 46 106 F 71 47 107G 72 48 110H 73 49 111I 74 4A 112| J 75 4B 113 K Equals Greater than Question mark At sign Uppercase A Uppercase B Uppercase C Uppercase D Uppercase E Uppercase F Uppercase G Uppercase H Uppercase l Uppercase J Uppercase K

The next line 25,

beq $t1, $zero, exit

If $t1 is equal to zero it means there length of the string is exceeded. In other words, for ex, string is 'ABCDEFG' totally 7 letters. So if $t0 is 8, then string($t0) value is 0 (zero).

The next line 26,

blt $t1 , 'A' , continue

blt means branch if less than.

So if the letter is less than 'A', or less than 65, then goto continue. The continue increments the value of $t0 by 1. This is done because only alphabets can be converted to small case and not symbols as seen in the table above.

The 27th line also is used for the same purpose, ie., If $t1 greater than 'Z', then it is a symbol so goto continue so than $t0 can be incremented.

The next table helps in in understanding the 28th line.

As you see the small letter 'a' has the ASCII decimal 97.

So the difference between small letter and capital letter is 97 - 65 = 32 in decimal. Converting decimal 32 to hexadecimal is 20, hence addi (addition) of 0x20.

The 29th line stores the converted letter to string($t0) in its respective positition.

This loop keeps running until no character is read, in other words, until 0 is read.

Comment for doubts.

Add a comment
Know the answer?
Add Answer to:
It's a MIPS question. Can anyone explain what's happened in the loop? Thank you. I need...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT