开发者

Mips, how do i print all the numbers greater than 10

How do I write a MIPS code to print all the numbers that larger than 10 in an array?

Assume:

  • the array exists in the memory block;
  • the starting address is in register $t0;
  • the size of the array is in regist开发者_StackOverflower $t1;

This is one of the questions appearing on my review sheet for the final exam, and I have no clue about it. Therefore, I hope anyone one good with MIPS can help me out with this.


If this is on your final exam study sheet then you should probably understand the basic syntax already, that said, you need to initialize a counter value, and set that in one of your temp registers, say $t2, you start it at zero. Each iteration through your code at the end you perform:

bgt $t2, $t1, BEGINNING_OF_LOOP

This tells you if you've looped through the array yet. You store 10 in one of your registers, say $t3, and each loop through the array you grab the value at $t0, increment the register by the length of a word, and check to see if the value is greater than 10:

lw $t4, $t0
addi $t0, $t0, 4
bgt $t4, 10, CODE_TO_PRINT_VARIABLE

This should get you on your way, but you are going to need to understand the basics of MIPS in order to answer a question like this. I suggest you write out this short program if you have time. If you can see the control structures in action at least once it helps cement the concepts in your mind. Hope this helps, good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜