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
Please find the answer below:::
.data
A : .word 300 #array of size 75 integer
B : .word 300 #array of size 75 integer
C : .word 300 #array of size 75 integer
.text
la $s0,A #get base address of A
la $s1,B #get base address of B
la $s2,C #get base address of C
li $t0,1 #load i =1
loop:
bge $t0,73,exit #if not i<73 exit
mul $t0,$t0,4 #get base address of i
add $t1,$t0,$s0 #get base address of A[i]
sub $t2,$t1,4 #get base address of A[i-1]
lw $t2,($t2) #get value of A[i-1]
add $t3,$t1,4 #get base address of A[i+1]
lw $t3,($t3) #get value of A[i+1]
add $t4,$t0,8 #get address of i+2
add $t4,$t4,$s1 #get address of B[i+2]
lw $t4,($t4) #get value of A[i]
lw $t1,($t1) #get value of A[i]
add $t5,$t0,$s2 #get address of C[i]
add $t6,$t1,$t3 #get A[i] + A[i+1]
sub $t7,$t4,$t2 #get (B[i+2] -A[i-1])
mul $t6,$t6,$t7 #get (A[i] + A[i+1])*(B[i+2] -A[i-1])
sw $t6,($t5) #store result to c[i]
add $t0,$t0,1 #i++
j loop
exit:
2) Write a MIPS assembly language version of the following C code segment: int A[75], B[75];...
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]; }
CDA-3101 – MIPS Assembly Programming 1. Write the following code segment in MIPS assembly language code: 3. Write a MIPS program to find the sum of squares from 1 to n. Where n=10. For example, the sum of squares for 10 is as follows: 12+22+32+……+n2=385
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
B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write MIPS assembly code segment for the following C code snippet for (i - 0, i < 100; i++) -array Register assignment: i-) $ao Base of array -> $s0 array [ i+1] [i] / 2; B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write...
1. [2 points] Write a MIPS assembly language program of the following C function and the code to call the function: int leaf_example (int g, h, i, j) { int f; f = (g + h) - (i + j); return f; مهه Arguments g, h, i, and j are passed to the function in registers $a0, $al, Şa2, and $a3, respectively while f in $50 (hence, need to save $50 on stack), and the result is to be stored...
x86 Assembly Language: Question 49 5pts Write a short code segment. Make your code as short as possible Create a macro named Mult16 that multiplies any two signed 16 bit memory operands and produces a 16-bit product. Assume the calculations are never exceeding 16 bits at any time. HTML B TVA. I Exaaxx - Du 01
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
B2. Translate the following MIPS assembly instruction into machine language: lw $t8, 100($s0) B3 Write MIPS assembly code segment for the following C code snippet: for (i - O i < 10i i++) i array[i+l] - array [i8; Register assignment: i-> Şa0 Base of array -> $s0 B2. Translate the following MIPS assembly instruction into machine language: lw $t8, 100($s0) B3 Write MIPS assembly code segment for the following C code snippet: for (i - O i Şa0 Base of...
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. Write the MIPS minimal sequence of instructions for the following C procedure code: int array_sum (a[], b[]) { int i; i =1; for (i=1; i<100; i=i+1) { b[i] = D + a[i-1] + a[i] + a[i+1] ;} } Assume that: a and b are arrays of words and the base address of “a” is in $a0 and the base address of “b” is in $a1, Register $S1 is associated with...