Question

Question 4) (12 Marks) This question is based on t
Question 4) (12 Marks) This question is based on t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution (a) Memory Content of the Code after execution [0x10010000] [0x10010010] [0x10010020] [0x10010030] [0x10010040] [0x1//Loop Loop: register t3-register t0 - 2 register t4 = register t0-1; register-t 1 = theAr ray [register-t3]; register t2 - t
Executable Code

//Headers.
#include <stdio.h>

//Array.
int theArray[40];

//Main().
int main()
{

    //Registers.
    int register_t0;
    int register_t1;
    int register_t2;
    int register_t3;
    int register_t4;
    int register_t5;
    int register_t6;
    int register_t7;

    //Initialization.
    register_t6 = 1;
    register_t7 = 1;

    //Save the first 2 terms of the sequence in theArray
    theArray[0] = register_t6;
    theArray[register_t7] = register_t6;
    register_t0 = 2;
   
    //Loop.
    Loop:
    register_t3 = register_t0 - 2;
    register_t4 = register_t0 - 1;
    register_t1 = theArray[register_t3];
    register_t2 = theArray[register_t4];
    register_t5 = register_t1 + register_t2;
    theArray[register_t0] = register_t5;
    register_t0 = register_t0 + 1;
    if (register_t0 < 40) goto Loop;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Question 4) (12 Marks) This question is based on the MIPS assembly code shown below. data...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First...

    MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First ask the user how many elements of his/her array. 2) Then, read the integer array elements as input from the User. 3) Then, print out the array before the sorting 4) Apply Bubble sort algorithm on your array 5) Print out the array after the sorting 6) Print some welcome text to th user 7) Add comments to your code to describe how is...

  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • 1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw        &

    1. For the MIPS assembly instructions below, what is the corresponding C statement? max:                    lw          $t0, 0($a0)         #load the first array value into $t0 addi      $t1, $0, 1            #intialize the counter to one loop:                   beq       $t1, $a1, exit     #exit if we reach the end of the array addi      $a0, $a0, 4         #increment the pointer by one word addi      $t1, $t1, 1          #increment the loop counter lw          $t2, 0($a0)         #store the next array value into $t2 slt          $t3, $t0, $t2       beq      ...

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

  • The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of...

    The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of using stack for storing/protecting registers. What is the mistake and how should it be fixed? Correct the corresponding lines in the code. For the corrected code, sketch the stack frame contents at the time when the instruction ‘move $s1, $a1’ is being executed. f:   addi $sp, $sp, 12 sw   $ra, 8($sp) sw   $s1, 4($sp) sw   $s0, 0($sp) move $s0, $a0 move $s1, $a1              #...

  • 2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp,...

    2. Q2 [25 points) Consider the MIPS code given in the following. main: addi Ssp, Ssp, -4 addi Sa0, $0, 2 sw $a0, 4(Ss1) addi Sal, $0, 3 sw Sal, 8(Ss1) jal dofsum sw SvO, 16(8s1) lw Sra, O(Ssp) addi Ssp, Ssp, 4 jr Sra dofsum: jal sum jr Sra sum: add SvO, Sa0, Sal jr Sra Draw the snapshot of the stack before, during, and after dofsum) function call. As- sume SSP, 0x45fff00 before dofsum() function call.

  • Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0....

    Compiling C Programs into MIPS Assembly and Machine Code sll $t1, $a1, 2 add $t1, $a0. $t1 lw $t0, 0($t1) lw $t2, 4($t1) sw $t2, 0($t1) sw $t0, 4($t1) 1. From the assembly code, what machine code might a MIPS assembler produce? 2. What does this program do? Write the C code for this assembly program.

  • can someone explain how you get the answer to this question? 1. Based on the following code segment what values are in the runtime stack immediately after the fourth time the instruction labeled...

    can someone explain how you get the answer to this question? 1. Based on the following code segment what values are in the runtime stack immediately after the fourth time the instruction labeled Rec is executed .text li Sa0, 7 jai Fact #assume the address of this instruction is 2000 fother code not shown Fact: addi Ssp, Ssp, -8 sw Sra, 4(Ssp) sw Sa0, 0(Ssp) slti St0, Sa0, 1 beq St0, Szero, Rec li SvO, 1 addi $sp, Ssp, 8...

  • MIPS assembly language question If $s0 has the base address of array A, and A has...

    MIPS assembly language question If $s0 has the base address of array A, and A has the following elements: 9, 6, 4, 24, 33, 0, 1; What is the value of $t1 after the instructions are executed? addi $t1, $zero, 20 add $t0, $t1, $S0 lw $t1, (Sto)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT