Solution: Please find below the code .file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .text .align 2 .globl func1 .set nomips16 .set nomicromips .ent func1 .type func1, @function func1: .frame $sp,48,$31 # vars= 0, regs= 6/0, args= 16, gp= 8 .mask 0x801f0000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-48 sw $31,44($sp) sw $20,40($sp) sw $19,36($sp) sw $18,32($sp) movz $31,$31,$0 sw $17,28($sp) sw $16,24($sp) .cprestore 16 blez $5,$L2 move $18,$5 move $16,$4 move $17,$0 li $19,1 # 0x1 $L4: lw $4,0($16) lw $25,%call16(func2)($28) nop .reloc 1f,R_MIPS_JALR,func2 1: jalr $25 nop lw $28,16($sp) bne $2,$19,$L3 nop addiu $20,$20,1 $L3: addiu $17,$17,1 bne $18,$17,$L4 addiu $16,$16,4 $L2: move $2,$20 lw $31,44($sp) lw $20,40($sp) lw $19,36($sp) lw $18,32($sp) lw $17,28($sp) lw $16,24($sp) j $31 addiu $sp,$sp,48 .set macro .set reorder .end func1 .size func1, .-func1
4. Consider the following C code and write its equivalent MIPS code [10 Marks] int func1...
Translate the following code into MIPS code. Test (int i, int j) { int k; k = Double(i+1) + Double (j-10) return k; } Sub (int m) { int g; g = m + m; return g; } Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.
Problem #2 (20pts) Please write the MIPS assembly code corresponding to the following C code segment. Assume that f is assigned to register $s2 int Example int i, int j, int k) int f; f i+j-k-1: return fi
Write an equivalent MIPS code for the following C code. Assume that the base address of an array A is stored in register 450. Variables x, i, j and h are stored in registers $t0,$t1, $t2 and $t3 respectively. do{ x = x + A[i]; i = i + j; } (while i != h); Make sure your MIPS code has sufficient comments.
1. Consider the following java code. int x 5 X++ Give equivalent MIPS ISA. Assume compiler will keep x in $s0 ($16) 2. What will be in $8 after executing the following statements? addi $8, $0, 5 add $8, $8, $8 What will be in $8 after execution? 2. addi $8, $0, 5 sll $8, $8, 2 shifting $8 left twice (logical shift- assume no sign) 4. What will be in $8 after execution? Assume $9 contains a valid RAM...
MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function
5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, answer the following: (a) Convert the above C code to MIPS assembly. (b) The condition you are testing is met at Case 1. You do not want the Case 2 to be tested. Add appropriate instructions in MIPS for this implementation. (c) If int x is any integer other than 1 or 2, you...
12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...
Write a MIPS assembly code that corresponds to the following C code. Note: use the stack to store all register values that you use in the procedures. int aver(int * array, int N){ int i, sum = 0; for ( i=0;i i<N; i++) sum += array[i]; return sum/N;} int Max( int * array, int N){ int i, Maximum = array[i]; for ( i = 1; i< N; i++) if ( array[i] > Maximum) Maximum = array[i]; return Maximum; } int...
what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...
MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value