Question

In: Computer Science

1. Convert the following pseudo code routine into MIPS assembler language: - Set register $t0 =...

1. Convert the following pseudo code routine into MIPS assembler language:

- Set register $t0 = 1

- In four separate instructions add 2, then 3, then 4, then 5 into register $t0

$t0 = $t0 + 2 + 3 + 4 + 5

- Copy the result from register $t0 into register $t1

2. Convert the following into MIPS assembler language:

- Set register $t0 = 0

- Initialize the register $t1 = 10

- Use register $t2 as a counter, and create a loop that repeats 5 times

- Each time through the loop, add register $t1 to $t0

- And add 10 (decimal) to register $t1

- As a result, $t0 should have the sum of the equation: 10 + 20 + 30 + 40 + 50

3. Generate an instruction sequence that will result in an arithmetic overflow. Do not use an endless loop, but rather create a specific code sequence.

Please add comments!!

Solutions

Expert Solution

1.
addi $t0 $zero 0x1 //set register $t0 =1
addi $t0 $t0 0x2 //add 2 to register $t0
addi $t0 $t0 0x3 //add 3 to register $t0
addi $t0 $t0 0x4 //add 4 to register $t0
addi $t0 $t0 0x5 //add 5 to register $t0
add $t1 $t0 $zero //$t1 = $t0+0

2.
addi $t0 $zero 0x0 //set register $t0 =0
addi $t1 $zero 0xA //set register $t1 =10
addi $t2 $zero 0x0 //set register $t2 =0

Loop:
   slti $t3 $t2 0x5 //set $t3 = 1 if $t2<5
   beq $t3 $zero end //if $t3 is not set branch to end
   add $t0 $t0 $t1 //$t0 = $t0+$t1
   addi $t1 $t1 0xA //$t1 = $t1+10
   addi $t2 $t2 0x1 //$t2 = $t2+1
j Loop //jump to Loop

end:

3.
MIPS integers are 32-bit, and since you'll be using signed integers, the maximum value is 2^31-1 . Thus any addition which results in a number larger than this should produce an overflow , e.g if you try to add 1 to 2147483647:

# Load 2147483647 into $s1
lui $s0, 32767
ori $s1, $s0, 65535

# Add 1 to $s1 and store in $s2. This should produce an overflow
addi $s2, $s1, 1


Related Solutions

Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only)....
Translate the C function code below to the MIPS True Assembler Language code (machine instructions only). The function code should follow the conventions for MIPS function calls including passing parameters and returning results. Your function code must be written with the minimum number of machine instructions to be executed and without any use of MIPS pseudo-instructions. Myfunction(unsigned int a, unsigned int b, unsigned int c) { int i=0; while (a > c) { a /= b; i++; } return i;...
Consider the following code: lb $t0, 1($t1) sw $t0, 0($t2) Assume the followings. • The register...
Consider the following code: lb $t0, 1($t1) sw $t0, 0($t2) Assume the followings. • The register $t1 contains the content 0x1000,0000. • The word at memory address 0x1000,0000 is 0xAABB,CCDD. What value of the word is stored at the memory address pointed to by register $t2? Show the value of the word in hexadecimal.
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”;...
Translate following pseudo-code to MIPS assembly language cout << “\n Please input a number for $s0”; cin >> $s0; cout << “\n Please input a number for $s1”; cin >> $s1; cout << “\n Please input a number for $s2”; cin >> $s2; $t0 = $s0 / 8 - 2 * $s1 + $s2; cout << “\n the Value of the expression “$s0 / 8 - 2 * $s1 + $s2” is ”; cout >> $t0; return;
produce the pseudo code for the Barber routine Clipaway() and the Customer routine Cutmyhair() such that...
produce the pseudo code for the Barber routine Clipaway() and the Customer routine Cutmyhair() such that each customer is given a customized haircut and each customer pays for the Barber’s service. The Sleeping Barber Problem This works for a shop that holds a total of N customers with one barber. If a customer cannot enter the shop, the customer will be forced into the street. Start the Barber before the customers. Shared variables: const int num_chairs = N; // number...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0,...
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0, $zero, -15 b. slt $t0, $s0, $s1 c. beq $t0, $zero, LEEQ d. j GRT
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
Translate the following Code into MIPS (.asm) Arrays and Reentrant Subprograms CallingSubroutinesDemo.asm Implement the following pseudo...
Translate the following Code into MIPS (.asm) Arrays and Reentrant Subprograms CallingSubroutinesDemo.asm Implement the following pseudo code in a program called SubRoutinePractice.asm. Be sure to follow proper protocol for calling subroutines. Implement a prolog and epilog. // Main routine asks for three numbers from the user. Stores them in $s0, $s1 and $s2 // It then calls a subroutine that determines the largest and sum. // Program then prints the results main() { // $s0, $s1 and $s2 hold input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT