Question

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!!

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022 ori $t0, $t0, 2048 srl $t1, $t0, 18 sw $t0, 101($t1) slti $t2, $t1, 5 beq $t2, $0, label3 label2:... ... label3:... a) The code modifies a word in memory at the following address (circle one): (i) 1022 (ii) 101 (iii) 5 (iv) 10220000 (v) Other (provide your own answer): _________________ b) The following value is stored in memory (circle one): (i) 0x17 (ii)...
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of...
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of MIPS instruction for the following pseudocode segment: A[3] = A[10] + B; Assume that B corresponds to register $t3 and the array A has a base address of 1000C41016 which is required to be loaded to register $t0 in your code. Provide comments for each line of your MIPS instruction. b) Assume that Loop starts at memory location 0xC010. Provide a) instruction format of...
1. Assume there are three memory locations named h hand area, translate the following expression into...
1. Assume there are three memory locations named h hand area, translate the following expression into MIPS assembly language. No Floating point. Area= 1/2 b. h 2. Show the assembly statement that allocates a word in the data segment named area with an initial value of 10. 3. What are the contents of register $t0, $t1, and $t2? .data str:    .asciiz   "ab" .text main:   la $t0, str li    $t1, 0 loop: lb $t2, ($t0) beqz   $t2, eloop addi $t1,...
Write the corresponding MIPS I instruction to the C++ code segment below. for (; i <...
Write the corresponding MIPS I instruction to the C++ code segment below. for (; i < 100; i ++) s = s + (2*i + 1); Use the table below for variable-register association Variable i s Register $t0 $t1 Variables s has been initialized with 0; i has been initialized with 1. No need to write instruction for their initializations. The instructions corresponding to the for-loop is labeled as "LOOP". The instructions following the for-loop is labeled by "DONE" (no...
I'm trying to write a nested loop in Mips Assembly that prints out, for example, if...
I'm trying to write a nested loop in Mips Assembly that prints out, for example, if user input x was 5: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (spaces in between) So far my code is : li $v0, 5   #Ask for integer syscall move $t5, $v0 addi $t0, $zero, 0 For1:    slt $t1, $t0, $t5    beq $t1, $zero, Exit    add $s0, $s0, $t0    addi $t0, $t0, 1...
Using MIPS Assembly language, sort 3 integers from greatest to smallest. Do this without using an...
Using MIPS Assembly language, sort 3 integers from greatest to smallest. Do this without using an array and instead use conditional branches, using the algorithm below: 1. Get Numbers From User 2.IF(#1 < #2) Swap the two numbers 3.IF(#2 < #3) Swap the two numbers 4.IF(#1 < #3) Swap the two numbers 5. Display Numbers in from greatest to smallest 6. End Program I have not been able to figure out the transfer of control when using branches and am...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If ( n is even) { n = n / 2; } else { n = 3 * n + 1; } In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT