int a = 200; // $1
int b = 500; // $2
int xMax = 1000; // $3
int yMax = 2000; // $4
if (xMax < a){
a = xMax;
}
if (yMax < b){
b = yMax;
}
How would I translate the above C code into MIPS assembly language?
using $1 as a, $2 as b, $3 as xMax, $4 as yMax, and $5, $6, ... as temporary variables. li $1, 200 # int a = 200; li $2, 500 # int b = 500; li $3, 1000 # int xMax = 1000; li $4, 2000 # int yMax = 2000; if1: bge $3, $1, end1 # if xMax >= a, then don't execute the loop body addi $1, $0, $3 # a = xMax; end1: if2: bge $4, $2, end1 # if yMax >= b, then don't execute the loop body addi $2, $0, $4 # b = yMax; end2:
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);
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...
2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75]; for (i = 1; i < 73; i ++) { C[i] = (A[i + 1] + A[i]) * (B[i + 2] - A[i-1]); } Arrays A, B and C start at memory location A000hex, B000hex and C000hex respectively. Try to reduce the total number of instructions and the number of expensive instructions such as multiplies. WRITE A SIMPLE CODE WORKING FOR MARS 4.5
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; }
In MIPS assembly, write an assembly language version of the following C code segment: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }
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...
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
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; }
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....
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