Question

In: Computer Science

The C language permits a variable to be left- or right-shifted by a nonconstant amount (e.g....

The C language permits a variable to be left- or right-shifted by a nonconstant amount (e.g. i >> j where i and j are variables), but the MIPS instruction set only supports shifts by a constant value (e.g. i >> 2). In words rather than code, describe how a variable-length right shift could be performed using MIPS instructions.

Solutions

Expert Solution

The MIPS instructions support the shifts operation by a constant value only. In C language the right shift is indicated by the symbol >>. In C, a variable can be left- or right-shifted by a variable value. In MIPS, a variable can be left- or right-shifted by a constant value. Example: i>>2. Here, the bits of the value i is right shifted by 2 positions.

  • In MIPS, a variable-length right shift operation can be done by using the bit variable-length shift registers. The length of the variable-length shift registers can be varied between the bits 0 to 64.
  • The variable-length right shift operation done by the instruction srlv (Shift word right logical variable).
  • The instruction srlv uses the variable length registers. This instruction shifts the value of a register to the right by the amount specified in another variable length register.

The syntax of this instruction is given below:

srlv $d, $t, $s

This instruction shifts the value in register $t to the right with the number of bits specified in the register $s and stores the result in register $d.

Consider the example, the following instruction shifts the value $t2 with 2 bits to the right, and places the result in $t3:

li $t1, 2               #load register $t1with 2

li $t2, 9422          # load register $t1with 9422    

                                   #$t2 = 0000 0000 0000 0000 0010 0100 1100 1110(in binary)

srlv $t3, $t2, $t1   # shifts the value $t2 with 2 bits to the right, and places the result in $t3

                                  #$t3 = 0000 0000 0000 0000 0000 1001 0011 0011


Related Solutions

Is language primarily controlled by the right or left hemisphere of the brain?
Is language primarily controlled by the right or left hemisphere of the brain?
Which of the patient’s limbs serves as an electrical ground? A)left arm b) right Arm c)right...
Which of the patient’s limbs serves as an electrical ground? A)left arm b) right Arm c)right leg d)left leg
Write a C# console program that fills the right to left diagonal of a square matrix...
Write a C# console program that fills the right to left diagonal of a square matrix with zeros, the lower-right triangle with -1s, and the upper left triangle with +1s. Let the user enter the size of the matrix up to size 21. Use a constant and error check. Output the formatted square matrix with appropriate values. Refer to the sample output below. Sample Run: *** Start of Matrix *** Enter the size of square (<= 21): 5 1 1...
wite a program in C to print a right and left pointing arrow pattern using '#'...
wite a program in C to print a right and left pointing arrow pattern using '#' symbol. Do so within 10 lines i.e upper half of the occupies 5 lines and lower half occupies other 5 lones. User will enter 'R' or'r' for printing right pointing arrow. 'l' or 'L' for left pointing arrow.'k'' for invalid option. You must use if-else and while loop for do this.
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
Demand curves usually slopes a. Downward to the left b. Downward to the right c. Either...
Demand curves usually slopes a. Downward to the left b. Downward to the right c. Either way is just as likely d. Straight upwards
IN C++ Given a struct Node { int value; Node *left, *right;}; , implement the functions...
IN C++ Given a struct Node { int value; Node *left, *right;}; , implement the functions below. a) int getSmallest(Node * r); // return smallest value in the BST with root r. Assume r not null. b) int getSecondSmallest(Node * r); // return 2nd smallest value in BST with root r. Assume r not null and r has a nonnull left or right child. c) void removeSecondSmallest(Node * r); // remove 2nd smallest value in BST with root r. Assume...
make a c++ program that calculates the amount left from a value of money of one...
make a c++ program that calculates the amount left from a value of money of one dollar bill or less in quarters, dimes, nickels, and pennies. The remaining value can be shown in cents knowing that in cents: penny = 1 nickel = 5 dime = 10 quarter = 25
Up Down Left Right Net Sales Revenue $         1,080,000 $ (d) 1,642,500 $ (j) Variable cost...
Up Down Left Right Net Sales Revenue $         1,080,000 $ (d) 1,642,500 $ (j) Variable cost (a) 100,000 1,314,000 143,100 Fixed Cost (b) 240,000 118,000 (k) Operating income (loss) $              87,000 $ (e) $ (g) 82,600 Units Sold 180,000 16,000 (h) (I) Contribution Margin per unit $                  3.00 $ (f) $        73.00 $    18.00 Contribution Margin Ratio ( c) 80% (i) 40% Net Sales Revenue 1,080,000 Variable costs ____________ Fixed costs ____________ Operating income (loss) 87,000 Units sold 180,000 Contribution...
Discuss any API / libraries of your favorite programming language (e.g. python, c#, java etc.) that...
Discuss any API / libraries of your favorite programming language (e.g. python, c#, java etc.) that you have used/reused in any of your previous projects and how it contributes to the overall project.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT