# Quick MIPS question regarding multiplication

Page 1 of 1

## 2 Replies - 1210 Views - Last Post: 07 February 2013 - 07:29 PM

### #1 userforgotten

Reputation: 0
• Posts: 2
• Joined: 06-February 13

# Quick MIPS question regarding multiplication

Posted 06 February 2013 - 08:26 PM

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:

(\$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

Is This A Good Question/Topic? 0

## Replies To: Quick MIPS question regarding multiplication

### #2 blackcompe

• D.I.C Lover

Reputation: 1156
• Posts: 2,538
• Joined: 05-May 05

## 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 userforgotten

Reputation: 0
• Posts: 2
• Joined: 06-February 13

## Re: Quick MIPS question regarding multiplication

Posted 07 February 2013 - 07:29 PM

Ok, thanks.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }