Hi; I know I have to multiply a register's value by 4, then add it to the address of an array to get the address of the [register's value]th element. We were taught to do the multiplication this way:
add $t0, $t0, $t0
add $t0, $t0, $t0
($t0 stores the # of the element)
However, my professor insists that we write code using as few instructions as possible. Thus, could I change the above two lines to:
sll $t0, $t0, 2
Quick MIPS question regarding multiplication
Page 1 of 12 Replies - 431 Views - Last Post: 07 February 2013 - 07:29 PM
Replies To: Quick MIPS question regarding multiplication
#2
Re: Quick MIPS question regarding multiplication
Posted 06 February 2013 - 10:22 PM
Well, you could of just ran the code to confirm the answer to your question, but yes that would work. Shifting a binary string to the left is the same as multiplying it by 2. Shifting to the right, divides by 2. Alternatively, you could have a mult instruction, but that's actually more work.
This post has been edited by blackcompe: 06 February 2013 - 10:24 PM
#3
Re: Quick MIPS question regarding multiplication
Posted 07 February 2013 - 07:29 PM
Ok, thanks.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|