6 Replies - 1554 Views - Last Post: 02 December 2012 - 08:02 PM

#1 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

MIPS beginner exercise question

Posted 02 December 2012 - 05:21 AM

Hello!

I'm working my way through a MIPS asm tutorial at the moment, but there are no solutions to the exercises.
I also have a little trouble understanding the questions, I don't know if it is my english skills, or
just the tutorial author being a little unclear. Anyway, here is the question, copied from the site.

Quote

Put the bit pattern 0x0000FACE into register $1. This is just an example pattern; assume that $1 can start out with any pattern at all in the low 16 bits (but assume that the high 16 bits are all zero).

Now, using only register-to-register logic and shift instructions, rearrange the bit pattern so that register $2 gets the bit pattern 0x0000CAFE.

Write this program so that after the low 16 bits of $1 have been set up with any bit pattern, no matter what bit pattern it is, the nibbles in $2 are the same rearrangement of the nibbles of $1 shown with the example pattern. For example, if $1 starts out with 0x00003210 it will end up with the pattern 0x00001230

A. Moderately Easy program: do this using ori instructions to create masks, then use and and or instructions to mask in and mask out the various nibbles. You will also need rotate instructions.

B. Somewhat Harder program: Use only and, or, and rotate instructions.


What I don't understand here is if I should do this with registers $1 and $2 only, or if can use other registers.
Would this assignment be possible with just 2 registers? I got it to work with 3 registers, going the "somewhat harder"
way, but if I'm meant to do it with 2 registers, then I can't consider myself done with this problem.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: MIPS beginner exercise question

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: MIPS beginner exercise question

Posted 02 December 2012 - 01:53 PM

You only need two. I think the intent here was to only use 2 as well.

  • Start with FACE in r1.
  • Mask C into r2.
  • Shift C left so that when you mask F into r2 you don't overwrite it and so that C is two bytes ahead of where F will reside.
  • Mask F into r2
  • Shift right so that F is the 2nd LSB in r2
  • Then mask A and E into r2.

Was This Post Helpful? 1
  • +
  • -

#3 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Re: MIPS beginner exercise question

Posted 02 December 2012 - 02:40 PM

Can I do that without using the immediate "andi" and "ori" instructions?
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: MIPS beginner exercise question

Posted 02 December 2012 - 02:47 PM

Not sure. The algorithm (above) can be done with andi and ori though.
Was This Post Helpful? 0
  • +
  • -

#5 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Re: MIPS beginner exercise question

Posted 02 December 2012 - 03:05 PM

I think the exercise were to do it without ori and andi, which I did, but with 3 registers.
Anyway, I have some doubts about another exercise from the same tutorial.

Quote

Start out a program with the instruction that puts a single one-bit into register one:

ori $1,$0,0x01

Now, by using only shift instructions and register to register logic instructions, put the pattern 0xFFFFFFFF into register $1. Don't use another ori after the first. You will need to use more registers than $1. See how few instructions you can do this in. My program has 11 instructions.


11 instructions? Am I misunderstanding the assignment or should I not trust this tutorial author to
be particularly experienced?

ori	$1, $0, 0x01
or	$1, $0, $0
nor	$1, $0, $0


Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: MIPS beginner exercise question

Posted 02 December 2012 - 03:57 PM

Quote

A. Moderately Easy program: do this using ori instructions to create masks, then use and and or instructions to mask in and mask out the various nibbles. You will also need rotate instructions.


The author explicitly said you could do it using andi or ori.

Quote

11 instructions? Am I misunderstanding the assignment or should I not trust this tutorial author to
be particularly experienced?


Haha. Yeah, he obviously missed that one. nor is a register logic instruction, so technically you solved it within the imposed constraints.

This post has been edited by blackcompe: 02 December 2012 - 04:00 PM

Was This Post Helpful? 1
  • +
  • -

#7 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Re: MIPS beginner exercise question

Posted 02 December 2012 - 08:02 PM

Quote

A. Moderately Easy program: do this using ori instructions to create masks, then use and and or instructions to mask in and mask out the various nibbles. You will also need rotate instructions.


The author explicitly said you could do it using andi or ori.


Well, ori, but I went for B.

"B. Somewhat Harder program: Use only and, or, and rotate instructions."

This post has been edited by DoNotWant: 02 December 2012 - 08:02 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1