Help me translate this C code into MIPS
int set(int n, int a[], int v)
{
int i;
for (i=4; i < (n-1); i++){
a[i] = v;
}
return i;
}
Given, Convert the given c code to the MIPS assembly code
C Code:
int set(int n, int a[], int v)
{
int i;
for (i=4; i < (n-1); i++)
{
a[i] = v;
}
return i;
}
Please check the below MIPS code which gives the proper functionality of the given c code.
MIPS Code:
set:
addiu $sp,$sp,-24
sw $fp,20($sp)
move $fp,$sp
sw $4,24($fp)
sw $5,28($fp)
sw $6,32($fp)
li $2,4 # 0x4
sw $2,8($fp)
b $L2
nop
$L3:
lw $2,8($fp)
nop
sll $2,$2,2
lw $3,28($fp)
nop
addu $2,$3,$2
lw $3,32($fp)
nop
sw $3,0($2)
lw $2,8($fp)
nop
addiu $2,$2,1
sw $2,8($fp)
$L2:
lw $2,24($fp)
nop
addiu $3,$2,-1
lw $2,8($fp)
nop
slt $2,$2,$3
bne $2,$0,$L3
nop
lw $2,8($fp)
move $sp,$fp
lw $fp,20($sp)
addiu $sp,$sp,24
j $31
nop
Please let me know in the comments if you need more help in this.
Help me translate this C code into MIPS int set(int n, int a[], int v) {...
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.
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...
Translate function f into MIPS assembly language. The code for function f is as follows: int func(int a, int b){ return a + b; } int f(int a, int b, int c, int d){ return func(func(a, b), c - d);
Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void change_global(int value) { counter = counter + value; } void main() { change_global(5); change_global(10); }
I need MIPS code for this program Translate the following C++ program to MIPS assembly program (Please explain each instruction of your code by a comment and submit a .asm file) // Example program #include <iostream> #include <string> using namespace std; int main() { const int ADULT_CHOICE= 1, CHILD_CHOICE= 2, SENIOR_CHOICE= 3, QUIT_CHOICE= 4, ADULT = 250, CHILD = 200, SENIOR = 350; int choice, months; int charges = 0; do { cout <<"\n\t\tHealth Club Membership Menu\n\n" <<"1. Standard Adult...
directly 3- Consider the C++ code below. Translate the code into MIPS instructions as possible. Put them in a file called program2.s. as int B[4] {300, 200, 100, 0 }; = int i = 3; B[i =BI01 + B[1] B 21; Run your code to make sure it has correct behavior. You should make sure the memory locations of the array hold the expected values.
directly 3- Consider the C++ code below. Translate the code into MIPS instructions as possible....
4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are arrays of size N elements, indexed 0..N-1 I=I; WHILE(I<N AND A[I]<B[I]) C[I] = A[I] + B[I-1]
C language to MIPS assembly code pleaseeeint hw_func (int num_hws, int avg_hours) {int total_hw_time;total_hw_time = num_hws x avg_hours;return total_hw_time;}int exercise_func (int num_exercises, int avg_hours) {int total_exercise_time;total_exercise_time = num_exercises x avg_hours;return total_exercise_time;}int total (int nhws, int hours, int nexercises, int ehours) {int total;total = hw_func (nhws, hours) + exercise_func (nexercises, ehours);return total;}void main( ) {int num_homeworks = 4;int average_hws_hours = 1;int num_exercises_per day = 2;int average_exercise_hours = 2;int total_time = total(num_homeworks, average_hws_hours,num_exercises_perday, average_exercises_hours);printf(“%d\n”, total_time);}
translate c++ to mips int get_singleton(int value) { //Declare and initialize int position = 0; bool isFound = false; //Loop while(!isFound) { //Update isFound = 1 & value; value = value >> 1; //Increment position++; } //Return return position; }
Translate the following piece of code into MIPS assembly. int x, y; int A=100, B=15, C=19, D=21; main(){ x = A + B; y = C + D; if (x > y) swap(&x,&y); } int swap (int *arg1,int *arg2) { int temp; temp = *arg1; *arg1 = *arg2; *arg2 = temp; }