-1

This was on an exam and I'll admit that I had no idea what was going on, shifts weren't discussed prior to the exam. They're both starting in hexadecimal and then the instructions shift one to the left logical and the other to the right arithmetic. For some reason the left logical one has every number plus 5 and then there's an 8 at the beginning, making the hex go from 7's to B's (12), and in the second one there's an E in the front but the numbers stay the same? My notes have the professor saying add two 0's or two 1's but I'm still not seeing where he got the answers from. The $t1 and $t0 values are given at the top and then below for each question is a different MIPS32 statement; sll $t2, $t1, 3 and sra $t2, $t0, 2. $t1 is in hex (0x7777 77777) and $t0 is (0x8888 88888).

enter image description here

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    Just putting it out there from experience, regarding where your professor got his answers from, the best answer will likely come from your professor. Professors usually lean kindly to students who send them an email, inquire in their office hours, ask questions in class. Even if you get a satisfactory answer here, it would likely flatter and make a good impression on your professor to ask your questions directly to them, and your professor's answer, along with the student-professor dialogue will likely leave you with a deeper understanding than from strangers on a Q&A website. – chickity china chinese chicken Nov 16 '21 at 00:17
  • Trust me, random people on the internet are better than this guy, he won't even answer questions during a lecture. –  Nov 16 '21 at 00:24

1 Answers1

1

For starters, B is 11 so it's not 7+5. Also, you seemed to be doing addition, not shifting.

First convert the number to binary. Shifting left brings in zeroes from the right, so append 3 zeroes and chop off 3 leading bits from the front. Convert the number back to hex. You will see all the digits except the last get turned to B (because they pull in bits of the following 7). The last digit obviously has the 3 zeroes you appended so that ends up being 8.

Arithmetic shift right duplicates the most significant bit. In your case that's a 1, so prepend two 1 bits and chop off two bits from the right. While that does give 1110=E at the front, the rest of the digits will be 0010=2 not 8. The correct result is E2222222.

Jester
  • 56,577
  • 4
  • 81
  • 125